# Set Interval script issue

**URL:** <https://forum.kirupa.com/t/set-interval-script-issue/158>\
**Category:** flash\
**Created:** [July 7, 2002, 11:40pm UTC](https://forum.kirupa.com/t/set-interval-script-issue/158 "2002-07-07T23:40:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sprntrl](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@sprntrl](https://forum.kirupa.com/u/sprntrl)\
**Post date:** [July 7, 2002, 11:40pm UTC](https://forum.kirupa.com/t/set-interval-script-issue/158/1 "2002-07-07T23:40:54Z")

</div>

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++;  
}

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 7, 2002, 11:51pm UTC](https://forum.kirupa.com/t/set-interval-script-issue/158/2 "2002-07-07T23:51:30Z")

</div>

because you reset counter to 1 each time.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 8, 2002, 1:24am UTC](https://forum.kirupa.com/t/set-interval-script-issue/158/3 "2002-07-08T01:24:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 8, 2002, 3:37am UTC](https://forum.kirupa.com/t/set-interval-script-issue/158/4 "2002-07-08T03:37:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 8, 2002, 3:11pm UTC](https://forum.kirupa.com/t/set-interval-script-issue/158/5 "2002-07-08T15:11:50Z")

</div>

```auto
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:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 8, 2002, 8:45pm UTC](https://forum.kirupa.com/t/set-interval-script-issue/158/6 "2002-07-08T20:45:13Z")

</div>

or:

```auto

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).
