Shifting a sprite via a button :(

Hey guys im currently workin on a game in my spare time and have come across a few problems. I’ve gone back to basics to figure out a redesign of my code using functions.

Here’s my initial problem:

I have a button, which when pressed will shift a sprite 100px to the right. I wanted it so that everytime i pressed the button, the sprite moved a further 100px from it’s stopped location. So basically if it’s moving and you push the button again, it’ll do nothing. It has to be stationary in order to move. At the moment my code shifts the sprite when the button is pressed, but it just keeps moving forever and doesn’t stop :frowning:

I’m very new to functions so i’m just figuring out the basics so i can apply this elsewhere :slight_smile:


_root.attachMovie("sprite", "sprite", 10000);

sprite._x = 25;
sprite._y = 25;
pushed = false;

var endX;
var stepX;

function right(stepX, endX, clip) {
    endX = sprite._x+100;
    stepX = (endX-sprite._x)/10;
    if (clip._x<endX) {
        clip._x += stepX;
    }
}

sprite.onEnterFrame = function() {
    if (pushed == true) {
        right(stepX, endX, this);
    }
};

I appreciate any help you guys can offer! :slight_smile: