-
Constrain Dragging
I have an object that needs to be dragged, but I need to constrain where it can be dragged to.
I need to only move on the X Axis - Left and Right,
And I need it to not be able to go past the right side of the stage, and then to not be able to go past an X value of 50.
Any ideas? Suggestions? Advice? Help? Thanks.
-
ummm...just add in the startDrag constraints...
startDrag(target:Object, [lock:Boolean, left:Number, top:Number, right:Number, bottom:Number]) : Void
Hope that helps...
-
Thanks, but I get an argument mismatch error with that.
evt.target.startDrag(false, 50, 0, stage.stageWidth-50, stage.stageHeight);
that's my code. Any further ideas? Thanks.
-
Are you using evt and target as your instance names to refer to the clip you want to drag?? Not sure why you would get an error...does the startDrag without the parameters work?
-
Yes, without the parameters it does work, yet if I add the parameters everything messes up.
I have that within a function called startDragFunc:
function startDragFunc(evt:Event):void {
evt.target.startDrag();
}
See anything wrong? Thanks again.
-
Have you tried testing it with hard-coded values to see if it's the stage references causing the problem?
Try:
evt.target.startDrag(false, 50, 0, 150, 0);
I think it's Stage.width and Stage.height...try that too
Hope that helps...
-
No Luck, any more ideas? Thanks.
-
Ah...try this...set a rectangle and set the bounds to that:
http://board.flashkit.com/board/showthread.php?t=755576
Hope that does it...
-
Thanks again, but still no luck, I tried the rectangle thing, and for some reason I can still drag it on the x and y axis. Any other ideas? Thanks.