Flash MX Script Help

  • Started
  • Last post
  • 2 Responses
  • autonoma

    I'm trying to move an MC to a certain point with a button using the following code:

    speed = 5;
    function boxOneMoveTo() {
    boxOne._y -= (boxOne._y-boxOneY)/speed;
    if (boxOne._y == boxOneY) {
    delete this.onEnterFrame;
    }
    }
    buttonOne.onRelease = function () {
    boxOneY = 90;
    boxOne.onEnterFrame = boxOneMoveTo;
    }

    The problem I'm having is, apparently, boxOne never lands EXACTLY on 90, so that if statement is never fulfilled. I want to determine when boxOne lands where it's supposed to so I can kill that onEnterFrame loop. I don't want scripts looping all over the place.

    How can I tell Flash to delete that onEnterFrame when boxOne gets, say, within .5 pixels of it's destination? Or, better yet, how can I force it to land EXACTLY on 90?

  • o0o0

    Instead of:

    boxOne._y -= (boxOne._y-boxOneY)/speed

    make yourself a var:

    var diff = boxOne._y-boxOneY;

    then go:

    boxOne._y -= diff/speed;
    if(diff <= 0.5){etc...}

    make sense?

  • arlo0

    Round the positioning to an integer using Math.round()