Groups | Blog | Home
all groups > flash actionscript > june 2004 >

flash actionscript : Is there a way to clear all intervals?


tygr
6/7/2004 9:17:48 PM
I have a situation where I could have several intervals active at once. Some
of these are created in nested clips using local variables to hold the IDs. I
would like a global button handler at the root level to clear all these
intervals, sort of like a stopAllSounds(). Is this possible? Using FlashMX.
Thanks!

Ty

urami_
6/8/2004 8:34:16 AM
[quoted text, click to view]

If you ID them say ID1 , ID2 , ID3 etc... you could for loop all at once.

For example :

ID1 = setInterval(myFun1, 2000);
function myFun1() {
trace("MyFun1");
}
ID2 = setInterval(myFun2, 2500);
function myFun2() {
trace("MyFun2");
}
ID3 = setInterval(myFun3, 3000);
function myFun3() {
trace("MyFun3");
}


To for loop all 3 :

on (release) {
for (i=1; i<=3; i++) {
clearInterval(ID+i);
}
}

<=3 stands for number of items to loop , if you have 10 intervals than <=10


--

Regards


urami_*



<no>
http://flashfugitive.com/
</no>

tygr
6/8/2004 4:47:51 PM
Thanks, urami, but I don't see how that code would work. Wouldn't the
statement:

clearInterval(ID+i);

take the value of ID, add i to it, and try to clear an interval id (likely
bogus) other than the one intended? Also, since intervals could be set inside
nested clips at any arbitrary level, would not those IDs be out of scope to a
script in, say, a root frame? Wouldn't I need a reference such as
clearInterval(clip1.clip2. ... clipn.IDn)? What I'm thinking of doing is
setting up a global array an index in the root like:

var aTimerIDList = new Array();
var nTimerIDIndex = 0;

Then to set a new interval id inside a nested clip:

_root.aTimerIDList[_root.nTimerIDIndex] = setInterval(...);
_root.nTimerIDIndex++;

And to clear 'em all in a handler at any level:

for (i = 0; i < _root.nTimerIDIndex; i++) {
clearInterval(_root.aTimerIDList);
}

_root.nTimerIDIndex = 0;

My next thought is if this is really necessary if the nested clips that set
these intervals are uninstantiated. What happens if I set an interval in a
frame script inside a nested clip, hold the ID in a local variable, and then
that clip is unloaded or the play head moves to a frame in the parent clip
where the child clip is no longer on the stage? The lifetime of the variable
holding the interval ID is over. Is the interval still trying to fire?

I'd appreciate any input on this. Thanks!!

Ty

AddThis Social Bookmark Button