HELP with AS moving an object and stopping

i’m trying to move an object on the main timeline after a button has been released. I have found the following script to make the object move by itself with no button:


onClipEvent(enterFrame) {
	speed = 1;
	_root.clip_mc._x += speed;
}

but i would like that object to move based on the events of a button, then stop at a certain point. then if another button is pressed, move again to another point and stop.

how can i modify this to help me out?

look at this sample nav i’ve put together. the button AS and mc AS are what’s important.

thats exactly what i’m looking for. i’m not exactly sure how this is working. would you mind explaining the code a little? i see “numba” in there and and “divider”. are these a couple of variables you have made up?

thanks…this will work great

glad it’s what you want, now for the explanation:
-divider is basically the speed. it’s a variable i made up.
-numba is the destination y value. also a variable i made up. when you click on a button, it will change the destination y value.
-y is another variable i made up.

basically you’re taking the difference between the destination y and the actual y. then dividing that number by the speed. you do this continuously through the onClipEvent(enterFrame) until destination y and actual y are equal.

if you’re going to do this for dynamic text using a pixel font, i would recommend using:
this._y=Math.round(this._y); as the last statement in your onClipEvent(enterFrame) command.

thats awesome. i will be using it to make a sliding MC activated by the buttons. so the whole window will be one screen, then when you hit one of the navigation links, the whole screen will slide into another position and take you to a different part of the site. Thanks again! u rock

no problem. good luck with that. you can obviously use that for _x too. it’s a really convenient way of moving and resizing things. my site for instance uses it to resize boxes (replace the _x with _width; _y with _height).