MouseEvent.MOUSE_DOWN 通过 mx:TextInput
我正在开发一个简单的 Flex / AIR 应用程序,只有一个 mx.TextInput 控件和一些按钮。 我没有使用系统chrome。
或多或少的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 上时,窗口才可拖动,而不是在其他控件上。
I'm working on a simple flex / AIR application with just a mx.TextInput control and some button. I'm not using the system chrome.
less or more the mxml is this:
<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>
To make the window draggable i've added a MouseEvent.MOUSE_DOWN listener to the TitleWIndow:
win.addEventListener(MouseEvent.MOUSE_DOWN, function(e:MouseEvent):void { stage.nativeWindow.startMove();});
The problem now is that the inner textinput control seems to inherit the eventlistner, so you can type text, but you can't select it (Cause holding down the mouse trigger the NativeWindow.move() function).
Am I missing something ? I want the window to be draggable only when i mousedown on the TitleWindow, not on other controls..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该检查事件对象的
target
属性,如下所示:否则,您还会捕获从内部元素(例如 TextInput)冒泡的 mouseDown 事件。
You should check the
target
attribute of the event object, like this:Otherwise you also catch mouseDown events bubbling up from inner elements such as the TextInput.