1

我正在开发一个简单的 flex / AIR 应用程序,只有一个 mx.TextInput 控件和一些按钮。我没有使用系统镀铬。

或多或少的mxml是这样的:

    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="495" height="316" creationComplete="init()">
    <mx:TitleWindow width="481" height="84" layout="absolute" horizontalCenter="0" showCloseButton="false" id="win" top="10">
        <mx:Label text="blahhh" id="label1" left="0" top="0"/>
        <mx:TextInput id="textinput1" left="155" top="0" right="5"  editable="true" />
        <mx:Label text="expand" right="36" bottom="0" click="toggleState()"/>
        <mx:Label text="exit" click="stage.nativeWindow.close()" right="0" bottom="0"/>
    </mx:TitleWindow>
</mx:Application>

为了使窗口可拖动,我在 TitleWINdow 中添加了一个 MouseEvent.MOUSE_DOWN 侦听器:

win.addEventListener(MouseEvent.MOUSE_DOWN, function(e:MouseEvent):void { stage.nativeWindow.startMove();});

现在的问题是,内部的textinput控件似乎继承了eventlistner,所以你可以输入文本,但是你不能选择它(因为按住鼠标会触发NativeWindow.move()函数)。

我错过了什么吗?我希望只有当我在 TitleWindow 上鼠标按下时才可以拖动窗口,而不是在其他控件上。

4

1 回答 1

1

您应该检查target事件对象的属性,如下所示:

win.addEventListener(MouseEvent.MOUSE_DOWN, function(e:MouseEvent):void {
    if (e.target == win)
        stage.nativeWindow.startMove();
});

否则,您还会捕获从内部元素(如 TextInput)冒泡的 mouseDown 事件。

于 2009-01-18T22:22:34.450 回答