MX > How to make functions stop running?

Hi guys,

I’m new to actionscripting and would appreciate some help understanding how to move from one frame to another (once clips complete their actions). I had previously posted some questions regarding this matter, but I think the post got too long and confusing (at least to myself).

SO I’m starting over from scratch and want to go step by step so I can understand. I have a line clip on stage that I move down the screen and center and expand it at the same time to fit the width of the stage. Now I have this code for that:

[AS]
goDownAndCenter=function()
{
if(this._width != 720) {
if (this._y < 375) this._y += 20;
if(this._width < 720) this._width += 15;
if(this._x > (700 / 2)) this._x -= 15;
} else {
trace(“width = 720”);
}
}

// We assing the two lines the handlers to move up/down and center
// themselves along with expanding their width
line1.onEnterFrame=goDownAndCenter;
[/AS]

As you can tell, I want the function to stop when the line reaches the width of 720, but for some reason it doesn’t stop when it reaches the end and it keeps going. What can I do to make it work?

Thanks,

Lior

[AS]goDownAndCenter = function () {
if (width>=720) {
delete this.onEnterFrame;
} else {
width += 15;
if (this._x>(700/2)) {
this._x -= 15;
}
this._width = width;
trace(width);
}
};
line1.onEnterFrame = goDownAndCenter;[/AS]

I guess what I’m trying to say is how do I stop the enterFrame action from being called after the movement has been terminated. Right now if the movement is terminated and I want to go to frame 2, then it will keep calling the function and reloading frame 2 over and over and over.

The only way I’ve figured to cheat it would be to make the movement happen in frame 1 using the actionscript, but then at frame 2 have the same clip loaded at the final position with a new keyframe and no actionscript at all. Does this make sense at all?

Thanks again

Ahhhh!!! Thank you very much!!! :beam:

Check this

You’re welcome…