A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Constrain Dragging

Hybrid View

  1. #1
    Senior Member jweeks123's Avatar
    Join Date
    Mar 2006
    Posts
    1,124

    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.

  2. #2
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,929
    ummm...just add in the startDrag constraints...

    startDrag(target:Object, [lock:Boolean, left:Number, top:Number, right:Number, bottom:Number]) : Void

    Hope that helps...
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  3. #3
    Senior Member jweeks123's Avatar
    Join Date
    Mar 2006
    Posts
    1,124
    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.

  4. #4
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,929
    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?
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  5. #5
    Senior Member jweeks123's Avatar
    Join Date
    Mar 2006
    Posts
    1,124
    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.

  6. #6
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,929
    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...
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  7. #7
    Senior Member jweeks123's Avatar
    Join Date
    Mar 2006
    Posts
    1,124
    No Luck, any more ideas? Thanks.

  8. #8
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,929
    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...
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  9. #9
    Senior Member jweeks123's Avatar
    Join Date
    Mar 2006
    Posts
    1,124
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center