Actionscript To Repeat An Animation Three Times

I am looking to add an actionscript to a Flash movie so that the entire animation repeats itself three times and then stops. I currently have the entire animation inside one movie clip which is placed into the first frame (and only one frame) on the stage.

Does anyone know of an actionscript to perform this loop?

In the past I have simply copied and pasted the entire frames to mimic the loop, but this method adds additional file size that is not needed.

Thanks in advance to anyone and everyone who responds!

Todd

I would think one could achieve this by having a variable set to an integer, 0. Then run a while loop which checks that the initial variable is not higher than 3, and if that evaluates to true process the code in the loop, and somewhere in there just increment the variable by one.

Unfortunately I am not versed in writing actionscript. Do you know how to write this or do you know of a site that shows how to perform this task?

On the last frame of your MovieClip put the following code:

if (my_counter == undefined) {
   my_counter = 1;
} else {
   my_counter = my_counter + 1;
}

if (my_counter > 2) {
   stop();
}

That should give you the functionality you’re after.

You’ll need to add a keyframe to the last frame though so the code doesn’t migrate across all the frames.

Let me know how you get on. :slight_smile:

ferrari_chris,

This was exactly what I was looking for. Nice!

I really appreciate your help!

No problem. :slight_smile:

nice tip.

FYI ppl this is AS2 only. I got errors when I tried this in AS3.

this should work in as3

var my_counter;
if (my_counter == undefined) {
   my_counter = 1;
} else {
   my_counter = my_counter + 1;
}
 
if (my_counter > 2) {
   stop();   
}

you just need to add var my_counter;to the code provided by ferrari_chris