Here is a working sample for you!
========================================================
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2005/mxml" xmlns="*" mouseMove="doMouseMove()">
<mx:Script>
    <![CDATA[
        private var bIsDown:Boolean = false;
       private var lastX:Number;
       private var lastY:Number;

       private function doMouseDown() {
           bIsDown = true;
           lastX = mouseX;
           lastY = mouseY;
       }

       private function doMouseUp() {
            bIsDown = false;
       }

       private function doMouseMove() {
           if (bIsDown) {
               var deltaX:Number = mouseX - lastX;
               var deltaY:Number = mouseY - lastY;

               selector.x += deltaX;
               selector.y += deltaY;

               lastX = mouseX;
               lastY = mouseY;
           }
       }
    ]]>
</mx:Script>
   
    <mx:Box id="selector" width="200" height="200" backgroundColor="#FFCC00" mouseDown="doMouseDown()" mouseUp="doMouseUp()">
        <mx:Text text="{selector.x}" />
        <mx:Text text="{selector.y}" />
    </mx:Box>
</mx:Application>

========================================================
Just change the xmlns if u want to use Flex 1.5!

Regards
Sree

Brian McPheeters wrote:
box.x and box.y will give me the new top-left corner that the box was dragged to? >From my testing it seemed to just give me the starting x,y the object was at.
 
Brian


From: flexcoders@yahoogroups.com on behalf of Sreejith Unnikrishnan
Sent: Wed 12/14/2005 10:22 AM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Drag Box around a container

Depends on what the container is:
If you are using a canvas or other absolute position container, the top-left corner of the box is the box.x and box.y values.

It can get tricky if you are using any other container such as HBox, Form etc.

Brian McPheeters wrote:
I am trying to figure out the drag/drop controls so I can let the user move the Box control or something similiar around a container. I have the drag/drop portions working but I am unable to figure out the correct coordinates to give to the Box.move() method. I guess what I am looking for is the top left of where the Box was dragged to. Any suggestions on how to go about doing this? I have seen similar messages about this but the links they reference are now dead http://www.mail-archive.com/flexcoders@yahoogroups.com/msg03724.html.
 
Thanks
Brian



--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




YAHOO! GROUPS LINKS







--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




YAHOO! GROUPS LINKS




Reply via email to