A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [MX04] Draggable Movie Clip Borders, What am I doing wrong?

  1. #1
    Member
    Join Date
    Dec 2006
    Posts
    54

    [MX04] Draggable Movie Clip Borders, What am I doing wrong?

    I have little bungee ball(ball_mc) that is draggable when pressed is flung back to the center when released. I would like to make it so that when it gets to far from the center it automaticlly animates back to the center as it does when it is released. But the code that I have written doesn't seem to work, it all worked until I added the borders, what could I be doing wrong? Thanks in advance.



    code:

    import mx.transitions.Tween;
    import mx.transitions.easing.*;
    var xBall = Stage.width/2;
    var yBall = Stage.height/2;
    ball_mc._x = xBall;
    ball_mc._y = yBall;
    ball_mc.onRollOver = function() {
    ball_mc.gotoAndStop(2);
    };
    ball_mc.onPress = function() {
    ball_mc.gotoAndStop(1);
    ball_mc.startDrag();
    if (ball_mc._y < 325 || ball.mc._y > 25 || ball_mc._x > 25 || ball_mc._x < 525) {
    ball_mc.stopDrag();
    var xTween:Tween = new Tween(ball_mc, "_x", Elastic.easeOut, ball_mc._x, xBall, 15, false);
    var yTween:Tween = new Tween(ball_mc, "_y", Elastic.easeOut, ball_mc._y, yBall, 15, false);
    }
    };
    ball_mc.onRelease = function() {
    ball_mc.stopDrag();
    if (ball_mc._droptarget == "/starball_mc") {
    starball_mc.gotoAndStop("2");
    }
    if (ball_mc._droptarget == "/colorball_mc") {
    colorball_mc.gotoAndStop("2");
    }
    var xTween:Tween = new Tween(ball_mc, "_x", Elastic.easeOut, ball_mc._x, xBall, 15, false);
    var yTween:Tween = new Tween(ball_mc, "_y", Elastic.easeOut, ball_mc._y, yBall, 15, false);
    };


  2. #2
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    are you sure about these bounds?
    ball_mc._y < 325 || ball.mc._y > 25 || ball_mc._x > 25 || ball_mc._x < 525

    with a Stage of 780 by 480, the ball (which is dead center) is at _y: 240 and _x is 390
    which is smaller than 325 (for _y) and smaller than 525 (for _x) so it 'stops drag' right away.

    gparis

  3. #3
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    Also, once you change your '<' for '>', you'll need to ad some form of loop to constanly check the position of the ball, not just an onPress, which gets fired only once.

    gparis

  4. #4
    Member
    Join Date
    Dec 2006
    Posts
    54
    the stage was smaller so the bounds were right, but adding the loop made it work...thanks gparis

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