Skip to main content
Inspiring
December 15, 2006
Answered

Dragging Objects (stopping mouse from moving)

  • December 15, 2006
  • 3 replies
  • 298 views
Hello,

I am very stuck. I tried looking over my old Director scripts for help but I cant make anything of them to help them with Actionscript.

Basically what i want to do is, when i am dragging a a movie clip such as 'lungs_mc' i dont want the user to be able to drag it outside of a box called 'dragArea_mc' which has co ords of: w:560.0, h:538, x: 235, y:57.0.

Basically when the user drags lungs_mc to the edge of box it stops the user from moving the object outside this box, but they are still able ot move it inside of the box.

Any Suggestions??

If you dont know how to retrain 'lungs_mc' within 'dragArea_mc' then even retraining them within x and y co ords would be great and i will just use < and > for those.

Also 'lungs_mc' is on the _root and so is 'dragArea_mc'. They both must stay on the root to make the whole movie work.

It would be greatly appreciated if anyone could help as it would solve a massive problem for me

thanks a lot :-)

Lee
This topic has been closed for replies.
Correct answer blemmo
The startDrag method takes up to 5 parameters, where 4 of them can define a bounding box for the dragging:
lungs_mc.startDrag(false, LEFT, TOP, RIGHT, BOTTOM)

You can insert the values for the dragging borders there. The values are relative to the dragged MC's parent, so keep that in mind. If lungs_mc is inside dragArea_mc, you could use
lungs_mc.startDrag(false, 0, 0, dragArea_mc._width, dragArea_mc._height)

hth,
blemmo

3 replies

December 15, 2006
In addition to the top code example you can also set the start position to be the x and y cord. of the dragArea_mc if the area is correctly positioned with the top left corner placed on the registration mark.

lungs_mc.startDrag(false, dragArea_mc._x, dragArea_mc._y, dragArea_mc._width, dragArea_mc._height)
Inspiring
December 15, 2006
hey thanks

that works like a treat

:-D

i saw something like this in an earlier post but it wasnt explained too well and i was getting silly results.

yours works perfect

thanks
blemmoCorrect answer
Inspiring
December 15, 2006
The startDrag method takes up to 5 parameters, where 4 of them can define a bounding box for the dragging:
lungs_mc.startDrag(false, LEFT, TOP, RIGHT, BOTTOM)

You can insert the values for the dragging borders there. The values are relative to the dragged MC's parent, so keep that in mind. If lungs_mc is inside dragArea_mc, you could use
lungs_mc.startDrag(false, 0, 0, dragArea_mc._width, dragArea_mc._height)

hth,
blemmo