# clearInterval (help needed)

**URL:** <https://forum.kirupa.com/t/clearinterval-help-needed/35494>\
**Category:** flash\
**Created:** [November 14, 2003, 4:12pm UTC](https://forum.kirupa.com/t/clearinterval-help-needed/35494 "2003-11-14T16:12:39Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Inflicted](https://avatars.discourse-cdn.com/v4/letter/i/82dd89/32.png) [@Inflicted](https://forum.kirupa.com/u/Inflicted)\
**Post date:** [November 14, 2003, 4:12pm UTC](https://forum.kirupa.com/t/clearinterval-help-needed/35494/1 "2003-11-14T16:12:39Z")

</div>

I got this to work. But I also want to  
clear the interval on this MC.

```auto
function wait() {
    _root.createEmptyMovieClip("holder",1);
    holder._y = 120;
    holder.loadMovie("myClip.swf");
}
myInterval = setInterval (wait, 2000);

```

Can anyone help me with this?

Thanks

regards

---

<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:** [November 14, 2003, 4:23pm UTC](https://forum.kirupa.com/t/clearinterval-help-needed/35494/2 "2003-11-14T16:23:48Z")

</div>

[AS]function wait() {  
\_root.createEmptyMovieClip(“holder”,1);  
holder.\_y = 120;  
holder.loadMovie(“myClip.swf”);  
clearInterval(myInterval);  
}[/AS]

clearInterval(intervalID);

myInterval in your case would be your intervalID.

---

<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:** [November 14, 2003, 4:38pm UTC](https://forum.kirupa.com/t/clearinterval-help-needed/35494/3 "2003-11-14T16:38:12Z")

</div>

Thanks a lot lost,

I tried this also, but thought it had to be called after the variable.

```auto
myInterval = setInterval (wait, 2000);
clearInterval(myInterval);

```

I don’t realy understand why it’s put there.  
It works though!

Could you explain a little, if time?

regards

---

<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:** [November 14, 2003, 4:41pm UTC](https://forum.kirupa.com/t/clearinterval-help-needed/35494/4 "2003-11-14T16:41:04Z")

</div>

setInterval runs a function after the specified amount of time.

If you clear the interval before that time is up, no function will be run because the setInterval will be canceled out before it can run it.

So what you can do is run the clearInterval within the function you are calling, so that way the setInterval gets cleared after your function has already been called 🙂

---

<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:** [November 14, 2003, 4:41pm UTC](https://forum.kirupa.com/t/clearinterval-help-needed/35494/5 "2003-11-14T16:41:44Z")

</div>

though wait is **defined** before the interval is called, its the interval that actually **runs** wait, and is THEN that myInterval can be cleared and stopped… after its been run (which would happen after its been defined)

[edit] beaten to it 🙂 [/edit]

---

<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:** [November 14, 2003, 4:43pm UTC](https://forum.kirupa.com/t/clearinterval-help-needed/35494/6 "2003-11-14T16:43:04Z")

</div>

man sen, you said what i said in so much less words, and much more clearer.

you bastard 😛

---

<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:** [November 14, 2003, 4:44pm UTC](https://forum.kirupa.com/t/clearinterval-help-needed/35494/7 "2003-11-14T16:44:12Z")

</div>

you think its clearer? After I posted it I read it (I only read what I put After I post heh) and I confused myself 😛 lol

---

<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:** [November 14, 2003, 4:47pm UTC](https://forum.kirupa.com/t/clearinterval-help-needed/35494/8 "2003-11-14T16:47:19Z")

</div>

perhaps i’m just used to reading your posts 😛

---

<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:** [November 14, 2003, 4:57pm UTC](https://forum.kirupa.com/t/clearinterval-help-needed/35494/9 "2003-11-14T16:57:59Z")

</div>

Thanks both of you,

I still have to configure my brain a little more  
to see the logic in this kind of issues.  
But it does sound logic.

good weekend,

regards
