tags:

views:

201

answers:

2

when I use startDrag() and stopDrag() to drag an object why doesn't it effect the x,y coordinates of the object?

you can run this example and see for yourself (move the circle and look at the trace messages):

<fx:Script>
    <![CDATA[
        import mx.events.FlexEvent;

        private function mouseDown(event:MouseEvent):void {
            circle.startDrag(false, new Rectangle(0,0 , 400, 400));
        }


        private function mouseReleased(event:MouseEvent):void {
            circle.stopDrag();
            trace("ended drag X: " + circle.x + ", Y: " + circle.y);
        }


        protected function application1_creationCompleteHandler(event:FlexEvent):void
        {
            circle.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown) 
            circle.addEventListener(MouseEvent.MOUSE_UP, mouseReleased);
        }

    ]]>
</fx:Script>

<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>

<s:Rect id="target1" x="0" y="10" width="150" height="150">
    <s:fill>
        <s:SolidColor color="0xFF0000"/>
    </s:fill>
</s:Rect>

<s:Rect id="target2" x="200" y="10" width="150" height="150">
    <s:fill>
        <s:SolidColor color="0x00FF00"/>
    </s:fill>
</s:Rect>

<s:Graphic id="circle" x="200" y="200">
    <s:Ellipse height="100" width="250">
        <s:stroke>
            <s:SolidColorStroke color="0x000000" weight="2"/>
        </s:stroke>
        <s:fill>
            <s:RadialGradient>
                <s:entries>
                    <s:GradientEntry color="0x0056FF" ratio="0.00" alpha="0.5"/>
                    <s:GradientEntry color="0x00CC99" ratio="0.33" alpha="0.5"/>
                    <s:GradientEntry color="0xECEC21" ratio="0.66" alpha="0.5"/>
                </s:entries>
            </s:RadialGradient>
        </s:fill>
    </s:Ellipse>
</s:Graphic>

+1  A: 
this is a very helpful solution, but I still don't understand why the drag action doesn't update the X and Y by itself, is it a bug? or is it intentional?