tags:

views:

384

answers:

1

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..

+1  A: 

You should check the target attribute of the event object, like this:

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

Otherwise you also catch mouseDown events bubbling up from inner elements such as the TextInput.

David Hanak