Set Interval script issue

Can someone tell me why the following script causes my mc to duplicate every second but when it does it gets rid of/overwrites the instance before it. I’m trying to make an escalator and the stair gets half way up when the next step starts and deletes the one prior to it.

setInterval(stepoff, 1000);
function stepoff() {
counter = 1;
duplicateMovieClip(“step”, “step”+counter, counter);
counter++;
}

because you reset counter to 1 each time.

dont really need a/s for that… here is a very very simple version. It can be cleaned up to look just fine.

Inigo, I clicked on the link but zero files came up in winzip. Can you email the fla. [email protected]. As far as the counter should I initialize it to 1 prior to the function or jus get rid of the =1.

counter = 1 ;

function stepoff() { 
  duplicateMovieClip("step", "step"+counter, counter); 
  counter++; 
}

setInterval(stepoff, 1000);

I don’t think there will be a problem, but if there is, it might come from the fact that you define counter in this frame. I don’t know.

And concerning the reason why it was doing this, it’s just that you duplicated the step in the layer 1, or the level 1, and when you do so, Flash removes what previously was on that layer. Hence the increment in the counter.

pom
:asian:

or:


function stepoff() { 
   duplicateMovieClip("step", "step"+(counter++), counter); 
}

counter will be initialized as 1 in the first iteration. that means you won’t have a “step0” movie in level 0 (it will start with “step1” in level 1).