-
clear ALL Intervals ?
hi there,
i 'd like to know if there is a way to clear all Intervals in a movie with one command...
in my current project I use setInterval()
very often in different clips and though i cleanly put the corresponding clearInterval() commands in the script I realized, that on slow computers some of them don't get stopped...
which puts more weight on the CPU and sometimes slows down the comp very much.
is there a fix ?
tia
-
you could name them interval1, interval2,..., intervaln
and then:
trigger this:
for (i=1; i<=n; i++) {
clearInterval(_root["interval"+i]);
}
-
Cool Idea !
-
A more direct answer that doesn't require you to reprogram your interval names was obtained from the blog below. I've included the relevant snippet here but there are some other useful tidbits at Ted on Flex.
Code:
Or if you simply want to clear out all the Intervals within the Flash Player:
i = setInterval(function(){},100) + 1
while(i--){
clearInterval(i)
}
-
just push the timers into an array, then loop through the array to clear them all:
Code:
var timers:Array = new Array();
var i:Number = setInterval(....);
timers.push(i);
function clearAllIntervals(a:Array):Void
{
for(var i:Number=0; i<a.length; i++)
{
clearInterval(a[i]);
}
}
with that function, you can then just call, clearAllTimers(timers); and it will do the job.
-
The advantage to the code that I posted is that it doesn't require any changes to your current code. You can simply drop the function in and it will clear out all of the intervals. Of course, your way is probably cleaner, but sometimes nuking everything can be useful. :-)
Also, how funny is it that this thing went dead for 5 years, then I replied and within 1 hour someone else replied? Crazy. Sorry to bring back an old thread, but it turned out to be applicable to my current problem (I stumbled across this forum through a Google search for the solution).
-
Oh, haha, I did not even look at the date!
I guess the same principals still apply.
-
@ Phoenix00017
Your "i = setInterval(function(){},100) + 1" code just saved me hours of headache.
I've had a nested clip with a pausei function that wouldn't clear/null and was coming in conflict with "_root.gotoAndPlay("page"+_root.page);" code.
I've spent almost two days on it... and nothing I found worked until I tried this.
THANK YOU!!!!!!
-
Well, credit goes to the blog I quoted from, but awesome to hear it helped. :)
Also, I find it again hilarious that this thread manages to rise from the dead to be helpful for a second time. Check out the years of the posts: 2002, then nothing until 2007, then nothing until 2011. Crazy!
-
Coolness
Yeah, I noticed that. Ten years almost.
I need to convert all this code to AS3, eventually. Just barely got a handle on AS2 when everything switched to AS3... But just glad I could find the info still.