Skip to main content
Participant
November 13, 2012
Answered

Flex 3: Problem Dragging a Component

  • November 13, 2012
  • 1 reply
  • 1360 views

Hi,

I created an MXML component that I want to be able to move around.

I added a button and I capture the mouse down & mouse up events:

protected function btnMove_mouseDownHandler(event:MouseEvent):void

{

     startDrag(false, new Rectangle(0, 0, parent.width - width, parent.height - height));

     event.stopImmediatePropagation();

}

protected function btnMove_mouseUpHandler(event:MouseEvent):void

{

     stopDrag();

     event.stopImmediatePropagation();

}

However, after the mouse is released, the component jumps back to the original location.

I can't get it to stay at the (x,y) it was released!

Any ideas???

Thanks!

This topic has been closed for replies.
Correct answer Alex J Harui

The “right” and “top” constraints are probabaly still in effect.

1 reply

Adobe Employee
November 13, 2012

Is it parented by a Canvas? Otherwise, the layout will return it to where it was.

Ofer BarAuthor
Participant
November 13, 2012

Yes, it is parented by a Canvas. The structure is like this:

<mx:Canvas id="wbcanvas" width="100%" height="100%">

     <mx:Canvas id="drawarea" clipContent="true" width="100%" height="100%">

     </mx:Canvas>

    <ui:MyMenu id="_menu" right="5" top="0" />

</mx:Canvas>

MyMenu.mxml (component that needs to be dragged):

<mx:Canvas

          xmlns:mx="http://www.adobe.com/2006/mxml"

          width="318" height="24"

     cornerRadius="0"

          backgroundAlpha="0.0"

     verticalScrollPolicy="off" horizontalScrollPolicy="off"

          buttonMode="true"

          >

....

</mx:Canvas>

Thanks!

Alex J HaruiCorrect answer
Adobe Employee
November 13, 2012

The “right” and “top” constraints are probabaly still in effect.