# setInterval

**URL:** <https://forum.kirupa.com/t/setinterval/29675>\
**Category:** Uncategorized\
**Created:** [August 29, 2003, 4:38am UTC](https://forum.kirupa.com/t/setinterval/29675 "2003-08-29T04:38:36Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![DrewJitsu](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/drewjitsu/32/294_2.png) [@DrewJitsu](https://forum.kirupa.com/u/DrewJitsu)\
**Post date:** [August 29, 2003, 4:38am UTC](https://forum.kirupa.com/t/setinterval/29675/1 "2003-08-29T04:38:36Z")

</div>

Hey,

I have a movie with the main content loaded on \_level1. In this movie I have a function:  
[AS]intervalID = setInterval(advPhoto, 2000);[/AS]  
when I load a different movie into that level then load the previous one again, the function is still triggered. If I trigger the fuction again it just doubles up and I can only stop the second instance.

I would’ve though that unloading the movie would kill the setInterval on this level.

I have tried to clearInterval(intervalID) when the movie loads.

Any Ideas?

---

<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:** [August 29, 2003, 4:53am UTC](https://forum.kirupa.com/t/setinterval/29675/2 "2003-08-29T04:53:06Z")

</div>

Would you post the whole code? 🙂

---

<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:** [August 29, 2003, 4:58am UTC](https://forum.kirupa.com/t/setinterval/29675/3 "2003-08-29T04:58:14Z")

</div>

sure…  
[AS]hiddenButton.onRelease = function() {  
buttonswitch();  
};  
buttonState = false;  
function buttonSwitch() {  
if (buttonState == false) {  
intervalID = setInterval(advPhoto, 2000);  
buttonAnim.gotoAndStop(2);  
buttonState = true;  
} else {  
clearInterval(intervalID);  
buttonAnim.gotoAndStop(1);  
buttonState = false;  
}  
}  
function advPhoto() {  
changePhoto(1);  
}  
[/AS]

---

<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:** [August 29, 2003, 5:10am UTC](https://forum.kirupa.com/t/setinterval/29675/4 "2003-08-29T05:10:18Z")

</div>

Well, the code seems to be fine. Which means that (kind of obvious (but I didn’t know!)) the interval is not cleared. Can’t you just clear the interval before you load the new movie?

---

<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:** [August 29, 2003, 5:14am UTC](https://forum.kirupa.com/t/setinterval/29675/5 "2003-08-29T05:14:25Z")

</div>

i did try that…

[AS]on (release) {  
loadMovie(“gallery.swf”, 1);  
\_level1.clearInterval(intervalID);  
}  
[/AS]

This code is on the button that loads the movie to level1

but to no avail…

wierd.

---

<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:** [August 29, 2003, 5:21am UTC](https://forum.kirupa.com/t/setinterval/29675/6 "2003-08-29T05:21:01Z")

</div>

Try to clear the interval **before** you call the loadMovie method.  
[AS]on (release) {  
\_level1.clearInterval(intervalID);  
loadMovie(“gallery.swf”, 1);  
}[/AS]  
I’m not sure though… :-\

---

<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:** [August 29, 2003, 5:23am UTC](https://forum.kirupa.com/t/setinterval/29675/7 "2003-08-29T05:23:29Z")

</div>

yeah, I tried that too…

no luck

Ha… Is this frustrating you as well yet?

---

<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:** [August 29, 2003, 5:24am UTC](https://forum.kirupa.com/t/setinterval/29675/8 "2003-08-29T05:24:53Z")

</div>

Ehmm… Yes!

Could you attach the FLA?

---

<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:** [August 29, 2003, 5:37am UTC](https://forum.kirupa.com/t/setinterval/29675/9 "2003-08-29T05:37:59Z")

</div>

i have put up a quick example here

[http://www.in2corp.com/ftp/SetIntDramas.zip](http://www.in2corp.com/ftp/SetIntDramas.zip)

---

<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:** [August 29, 2003, 5:57am UTC](https://forum.kirupa.com/t/setinterval/29675/10 "2003-08-29T05:57:50Z")

</div>

Ok… I think you zipped the wrong test1.fla and test2.fla files… :crazy:

Anyway, try using this little function, it will clear every interval in the Flash movie.  
[AS]\_global.clearAllIntervals = function() {  
var i = 0, n = setInterval(arguments.callee, 10000);  
while (i++\<n) clearInterval(i);  
};[/AS]  
I repeat, it will clear them **all**.

Just call the function from anywhere in the movie.  
[AS]clearAllIntervals();[/AS]

---

<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:** [August 29, 2003, 6:15am UTC](https://forum.kirupa.com/t/setinterval/29675/11 "2003-08-29T06:15:19Z")

</div>

MAN THIS THING WILL NOT DIE!!!..

i have put it in the first frame of the loaded movie.  
I have tried it on the button.

This is wierd.

i have updated the zip  
[http://www.in2corp.com/ftp/SetIntDramas.zip](http://www.in2corp.com/ftp/SetIntDramas.zip)

---

<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:** [August 29, 2003, 6:26am UTC](https://forum.kirupa.com/t/setinterval/29675/12 "2003-08-29T06:26:33Z")

</div>

I’m so stupid!! 😛  
[AS]on (release) {  
clearInterval(\_level1.intervalID);  
loadMovie(“test2.swf”, 1);  
}[/AS]  
…This is the second time tonight that I didn’t see the error. :-  
I really should go to bed. 😛

---

<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:** [August 29, 2003, 6:30am UTC](https://forum.kirupa.com/t/setinterval/29675/13 "2003-08-29T06:30:38Z")

</div>

YEAH.

thanks for helping me through the hell that is setInterval

appreciated.

Drew

---

<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:** [August 29, 2003, 6:33am UTC](https://forum.kirupa.com/t/setinterval/29675/14 "2003-08-29T06:33:06Z")

</div>

Hehe - You’re welcome. 😉

And now, I’m off to bed. :sleep:
