ActionScript 3: Resize and Drag

Dear experts,

I'm trying to develop an application to crop a picture.
Selecting the area of the picture to crop should work with a bounding box.
This box can be moved, and resized. Moving the box, already works.
With resizing it, I'm having problems.

I've added a MouseEvent.MOUSE_MOVE listener, which is called correctly. When I simply do a trace in my function, I get feedback everytime I move my mouse. However, when I add a statement that changes the width of my box, this statement is executed once and the script stops.
I have no clue why!

Below you can find my code:

--
boundingbox_mc.drag_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
boundingbox_mc.drag_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
boundingbox_mc.resize_mc.addEventListener(MouseEvent.MOUSE_DOWN, startResize);
boundingbox_mc.resize_mc.addEventListener(MouseEvent.MOUSE_UP, stopResize);

boundingbox_mc.drag_mc.buttonMode = true;
boundingbox_mc.resize_mc.buttonMode = true;

function pickUp(evt:MouseEvent):void{
      boundingbox_mc.startDrag(false);
}

function dropIt(evt:MouseEvent):void{
      boundingbox_mc.stopDrag();
}

function startResize(evt:MouseEvent):void{
      var sprite:Sprite = Sprite(evt.target);
      sprite.addEventListener(MouseEvent.MOUSE_MOVE, moveResize);
      sprite.startDrag(false);
}

function stopResize(evt:MouseEvent):void{
      var sprite:Sprite = Sprite(evt.target);
      sprite.stopDrag();
      sprite.removeEventListener(MouseEvent.MOUSE_MOVE, moveResize);
}

function moveResize(evt:MouseEvent):void{
      var location:Point = new Point(evt.target.mouseX, evt.target.mouseY);
      location = evt.target.localToGlobal(location);
      trace(location.x - boundingbox_mc.x);
      boundingbox_mc.width = location.x - boundingbox_mc.x;
}
--

Any help is higlhy appreciated!
RoBAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Antonio EstradaTech Leader / Senior Web DeveloperCommented:
It does work, but since the resize_mc MovieClip is INSIDE the boundingbox_mc, they both get resized and you probably lose focus so it only does it once... So, take the resize_mc outside of the boundingbox_mc and try the following code:

<code>

-V
boundingbox_mc.drag_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
boundingbox_mc.drag_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
resize_mc.addEventListener(MouseEvent.MOUSE_DOWN, startResize);
resize_mc.addEventListener(MouseEvent.MOUSE_UP, stopResize);

boundingbox_mc.drag_mc.buttonMode = true;
resize_mc.buttonMode = true;

function pickUp(evt:MouseEvent):void{
      boundingbox_mc.startDrag(false);
}

function dropIt(evt:MouseEvent):void{
      boundingbox_mc.stopDrag();
}

function startResize(evt:MouseEvent):void{
      var sprite:Sprite = Sprite(evt.target);
      sprite.addEventListener(MouseEvent.MOUSE_MOVE, moveResize);
      sprite.startDrag(false);
}

function stopResize(evt:MouseEvent):void{
      var sprite:Sprite = Sprite(evt.target);
      sprite.stopDrag();
      sprite.removeEventListener(MouseEvent.MOUSE_MOVE, moveResize);
}

function moveResize(evt:MouseEvent):void{
      var location:Point = new Point(evt.target.mouseX, evt.target.mouseY);
      location = evt.target.localToGlobal(location);
      trace(location.x - boundingbox_mc.x);
      boundingbox_mc.width = location.x - boundingbox_mc.x;
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RoBAuthor Commented:
Thanks a lot for your answer Vulturous. Will check this first thing tomorrow morning.
Will get back to you...
0
IqAndreasCommented:
You might also want to look into the "Senocular Transform Tool". It does exactly what you are trying to do
http://www.senocular.com/?entry=372
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.