Actionscript 3: Drag constraints

  • Started
  • Last post
  • 5 Responses
  • CyBrain

    Is it possible to constrain a MOVIE CLIP (not sprite) to a specific area?

    If this were as2, it would be draggableMovieClip_mc.startDrag... left, top, right, bottom);
    where false means don't lockcenter and the other variables are previously set numbers.

    I'm getting this error when I try to drag my movie clip: "ArgumentError: Error #1063: Argument count mismatch on flash.display::Sprite/startDrag... Expected 0, got 5.
    at flv_test_fla::MainTimeline/start...

    If you can't drag a movie clip. How do I make my movie clip a sprite?

    Also, why did Adobe set me years behind in my scripting knowledge by overhauling the actionscript?

  • whiteout0

    a sprite cannot be existing on the stage, it must be attached
    var rect = new Rectangle(L, T, R, B);
    sprite.startDrag(false, rect);

    google - as3 startDrag

  • CyBrain0

    Ok. that makes sense, but suppose I have a movie clip symbol I like the look of. Can I use that as my draggable graphic and constrain the movement of dragging to L, T, R, B?
    or
    If I put a linkage name on my movie clip and attach use addChild to put it on the stage, will that allow me to constrain the drag? or is that new thing on the stage still considered a movie clip?

    Seems like actionscript is taking away a feature that existed since the beginning of its history, but that can't be right.

  • CyBrain0

    Ok I got somewhere by adding a new variable to my script like you said.
    var dragZone:Rectangle = new Rectangle(left, top, right, bottom);
    and then changing my other line to
    event.target.startDrag(false, dragZone);

    but the draggable area has quite a range for top and bottom.

  • akoni0

    you mean something like this?

    var circle:Sprite = new Sprite();
    circle.graphics.beginFill(0xFFCC...
    circle.graphics.drawCircle(80, 80, 40);
    addChild(circle);

    circle.addEventListener(MouseEve... mouseDown)
    circle.addEventListener(MouseEve... mouseReleased);

    var rectangle:Rectangle = new Rectangle(0,0, 100, 100);
    function mouseDown(event:MouseEvent):void
    {
    circle.startDrag(false, rectangle);
    }

    function mouseReleased(event:MouseEvent...
    {
    circle.stopDrag();
    }

  • CyBrain0

    Yeah, I tried using linkage for my movie clip to put it on the stage and call it a new Sprite, but everything freaked out.

    You'd think I could Google something as basic as this, but nothing gives. I've been trying to figure this out for hours.