views:

210

answers:

1

p2 = setInterval(function () { clearInterval(p2); some code here; }, waitTime)

I need to break out of this interval in a separate function.

This plays an array of SWF movies - there is a purge function that needs to stop this interval.

How can I stop this interval from a separate function in AS2?

+1  A: 

the whole thing with setInterval is scope.

the way your code looks, p2 is in the main timeline and it belongs to this/_level0/_root right ?

clearInterval() is a global function as well, so you can call it from any other function nested in any movie clip, as long as you can get access to the interval's id (p2 in your case)

so if you have some like:

p2 = setInterval(function () { trace('p2 running'); }, waitTime);

you can have a separate function like

function clearP2(){
clearInterval(p2);
}

if that function is nested in some clip you can always use the dirty all _root ( as in absolute path )

e.g. //clearP2 lives in a nested clip far far away from _root

function clearP2(){
clearInterval(_root.p2);
}

of course you can use relative paths as well

function clearP2(){
clearInterval(_parent._parent._parent.p2);//depending on the clips hierarchy
}

the idea to keep in mind is to make sure you can access the interval's ID where you need it, clearInterval() is global

George Profenza