Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
607 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...