# \[MX\] setInterval Bug?

**URL:** <https://forum.kirupa.com/t/mx-setinterval-bug/53520>\
**Category:** flash\
**Created:** [June 4, 2004, 6:15pm UTC](https://forum.kirupa.com/t/mx-setinterval-bug/53520 "2004-06-04T18:15:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![foochuck](https://avatars.discourse-cdn.com/v4/letter/f/dfb087/32.png) [@foochuck](https://forum.kirupa.com/u/foochuck)\
**Post date:** [June 4, 2004, 6:15pm UTC](https://forum.kirupa.com/t/mx-setinterval-bug/53520/1 "2004-06-04T18:15:04Z")

</div>

Hello,

I’ve been experiencing a problem using setInterval and I’m wondering if any Flash users out there have expierienced it and/or have come across a fix for this problem. Heres a description of the layout/problem:

Flash Movie 1: I have an empty movieclip in this movie that I load Flash Movie 2 into.

Flash Movie 2: Gets loaded into Flash Movie 1 into an empty movieclip. This movie contains a setInterval action that repeats indefinitly.

I open Flash Movie 1, press the button to load Flash Movie 2, Movie 2 performs as expected. The setInterval loop performs correctly.

Next I unload Movie 2 from Movie 1. During the unload I clear the interval thats happening in Movie 2. Now while I’m still in the same session I load Movie 2 back into Movie 1. The setInterval loop seems to be going even faster then before. I unload Movie 2 and repeat - loading it back into Movie 1 and now the setInterval is going even faster.

Yet each time the Interval is cleared. Now if I reset my movie by closing and reopening it the setInterval works fine the first time - but throughout the session as the movie containing it is loaded and unloaded the interval keeps going faster and faster each time.

Is this a bug in Flash MX? Does anyone know of a cure for this?

Thanks :rd:

---

<div class="post-metadata">

**Author:** ![Rob\_Hed](https://avatars.discourse-cdn.com/v4/letter/r/8e7dd6/32.png) [@Rob\_Hed](https://forum.kirupa.com/u/Rob_Hed)\
**Post date:** [March 29, 2006, 6:27pm UTC](https://forum.kirupa.com/t/mx-setinterval-bug/53520/2 "2006-03-29T18:27:50Z")

</div>

> [@foochuck](#):
>
> Alright Senocular,
> 
> Now press Load Movie 3 and this loads movie3.swf in place of movie2. Now load movie2.swf in again. If you go back and forth a couple times (I find if you load movie 3 when the interval is running and then load 2 back in) you’ll start to see that the 4 second gap after when movie 2 hits 99 alpha til its reset starts to get shorter and shorter. It gets cut down to a 2 second gap…like the interval was cut in half.
> 
> Any tips for what I could do to fix this?
> 
> Thanks!

I’m having the exact same issue. The interval in the loaded swf gets faster and faster even though I have a clearInterval in the loaded swf .

Did you solve this issue?

---

<div class="post-metadata">

**Author:** ![stringy](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@stringy](https://forum.kirupa.com/u/stringy)\
**Post date:** [March 29, 2006, 6:55pm UTC](https://forum.kirupa.com/t/mx-setinterval-bug/53520/3 "2006-03-29T18:55:56Z")

</div>

> [@Rob Hed](#):
>
> I’m having the exact same issue. The interval in the loaded swf gets faster and faster even though I have a clearInterval in the loaded swf .
> 
> Did you solve this issue?

clear the interval from the movie you are loading into before you load/reload a movie

```auto
btn.onPress = function() {
	clearInterval(container.intervalName);
	container.loadMovie("whatever.swf");
};

```

As a last resort you can just loop through a huge amount of numbers which although not so efficient will work

```auto
for (var i = 1; i<1000; i++) {
	clearInterval(i);
}

```

---

<div class="post-metadata">

**Author:** ![Rob\_Hed](https://avatars.discourse-cdn.com/v4/letter/r/8e7dd6/32.png) [@Rob\_Hed](https://forum.kirupa.com/u/Rob_Hed)\
**Post date:** [March 29, 2006, 7:30pm UTC](https://forum.kirupa.com/t/mx-setinterval-bug/53520/4 "2006-03-29T19:30:08Z")

</div>

> [@stringy](#):
>
> As a last resort you can just loop through a huge amount of numbers which although not so efficient will work
> 
> ```auto
> for (var i = 1; i<1000; i++) {
> clearInterval(i);
> }
> 
> ```

The latter did the trick. I wouldn’t have thought clearing the Interval on the main timeline would have worked. Thanks a ton…you saved me a lot of grief.

---

<div class="post-metadata">

**Author:** ![gameboys](https://avatars.discourse-cdn.com/v4/letter/g/7cd45c/32.png) [@gameboys](https://forum.kirupa.com/u/gameboys)\
**Post date:** [March 30, 2006, 1:35pm UTC](https://forum.kirupa.com/t/mx-setinterval-bug/53520/5 "2006-03-30T13:35:48Z")

</div>

I am struggeling with the same problem, but that last didn’t work for me. you just placed that in the main time line as a framscript?

---

<div class="post-metadata">

**Author:** ![stringy](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@stringy](https://forum.kirupa.com/u/stringy)\
**Post date:** [March 30, 2006, 7:03pm UTC](https://forum.kirupa.com/t/mx-setinterval-bug/53520/6 "2006-03-30T19:03:30Z")

</div>

> [@gameboys](#):
>
> I am struggeling with the same problem, but that last didn’t work for me. you just placed that in the main time line as a framscript?

Just stick it in a function and call the function whenever you need.If you have only used a couple of intervals in your external movie would be better to clear each individually.This is only a last resort solution.

---

<div class="post-metadata">

**Author:** ![grass](https://avatars.discourse-cdn.com/v4/letter/g/96bed5/32.png) [@grass](https://forum.kirupa.com/u/grass)\
**Post date:** [April 19, 2006, 11:06pm UTC](https://forum.kirupa.com/t/mx-setinterval-bug/53520/7 "2006-04-19T23:06:32Z")

</div>

dnx 2 da dude “stringy”!!!  
didn’t save me a lot of trouble - tried 2 find solution 4 my own but still, ended a really bugging problem…

i even tried clearInterval(my\_interval) in a main swf, but didn’t find relevant adding emptyMovieclip name b4 it…

in the main swf:  
clearInterval(empyMovieclip.my\_interval);  
worked fine.

dnx again 🙂

…I actually registered here 2 thank u man 😛

---

<div class="post-metadata">

**Author:** ![stringy](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@stringy](https://forum.kirupa.com/u/stringy)\
**Post date:** [April 20, 2006, 7:33pm UTC](https://forum.kirupa.com/t/mx-setinterval-bug/53520/8 "2006-04-20T19:33:51Z")

</div>

> [@grass](#):
>
> dnx 2 da dude “stringy”!!!  
> didn’t save me a lot of trouble - tried 2 find solution 4 my own but still, ended a really bugging problem…
> 
> i even tried clearInterval(my\_interval) in a main swf, but didn’t find relevant adding emptyMovieclip name b4 it…
> 
> in the main swf:  
> clearInterval(empyMovieclip.my\_interval);  
> worked fine.
> 
> dnx again 🙂
> 
> …I actually registered here 2 thank u man 😛

No problem, you may also be interested in this post by MichaelxxOA

> **[kirupaForum](https://forum.kirupa.com)**
>
> Got a web design/development question or just want to hang out with the most awesome people on the planet? Drop on in!

works well
