Movement using actionscript

Hi! Ive done the tutorial on how to make things move with actionscript
(http://www.kirupa.com/developer/mx/ASmovement.htm)

however this is just for continuos movement- does anyone know how you stop it moving?

i am a novice so please help!!

This thread might help you:

http://www.kirupaforum.com/forums/showthread.php?threadid=37377&highlight=tarX

Of course, if you want it to move in only one direction then get rid of the other one (x or y)

That’s easing, not continuous movement. But maybe that’s something mollie might like too. Anyway: to make the movement, you must delete the onEnterFrame handler.

The problem is that this can’t be done with static event handlers (on(enterFrame){…}). This can only be done using dynamic event handlers: yourmovieclip.onEnterFrame = function(){…}.

The code from the tutorial uses a static onEnterFrame handler, which means that you can’t delete the onEnterFrame handler to make the moving stop.


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

But by making this a dynamic event handler, you can easily delete it. It is done by giving the movieclip an instance name and using

movieclipname.onEnterFrame = function(){
//code goes here
}

So give the movieclip on your stage the instance name “moving” for example, and then place this code on the timeline (!) in which the button is on. Dynamic event handlers go on the timeline, unlike static event handlers which go on the movieclip itself.

For example, let’s say you want the movement to stop when the movieclip has reached an X position of 300:


moving.onEnterFrame = function(){
this._x++
if(this._x >= 300){
delete this.onEnterFrame
//the onEnterFrame handler is now deleted, and the moving will stop
}
}

thanks guys thats great :O)

You’re welcome :wink: