How does one break out of a Set Interval in Action Script 2

核能气质少年 提交于 2019-12-13 03:45:54

问题


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:


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



来源:https://stackoverflow.com/questions/1261977/how-does-one-break-out-of-a-set-interval-in-action-script-2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!