I’m trying to replicate the motion of a ‘mexican wave’. I am using Flash CS5, and using AS2.
I’ve created a ‘jumper’ graphic and animated it in a clip so it jumps once – up then falls back to the ground. I’ve pulled the clip in to the main timeline and replicated a bunch of times so I have a row of ‘jumpers’. I’ve given each instance a unique ID. Then I’m telling each clip instance to start playing, in sequence, using the following code:
var total_jumpers = 36;
var i = 0;
var jumpLag = 1000;
function do_jump(bottle) {
jumper.play();
}
for( i=1; i<=total_jumpers; i++)
{
var mcName:String = "b" + i;
jump = setInterval(do_jump,jumpLag,this[mcName]);
trace("Jumper " + mcName + ". Lag: " + jumpLag);
jumpLag += 100;
}
clearInterval(jump);
stop();
In the clip, I have put stop() in the last frame to try and stop it looping.
So this works ok, but the clips seem to loop – I can’t get them to stop.
I would be grateful for any insight / assistance.
setIntervalis probably not the best way to do this because it repeats continuously untilclearintervalis called..setIntervalreturns a different ID for each call – think of it as the unique ID for each timer.The code which calls
clearIntervalit’s actually only clearing the last interval.clearIntervalneeds to be called for each ID returned bysetInterval. This would require storing the IDs in an array, then calling theclearIntervalfor the specific ID after the animation has started.A better way to do this would be to use
setTimeout(see flash.utils.setTimeout) because it only runs once and then dies, meaning you will not need the extra logic to stop the timer.