如何在Action Script 2中突破设定间隔 [英] How does one break out of a Set Interval in Action Script 2

查看:78
本文介绍了如何在Action Script 2中突破设定间隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

p2 = setInterval(函数() { clearInterval(p2); 这里的一些代码; },waitTime)

我需要在一个单独的函数中突破这个间隔.

这会播放一系列SWF电影-有一个清除功能需要停止此间隔.

如何从AS2中的单独功能中停止此间隔?

解决方案

使用setInterval的整个过程就是作用域.

代码的外观,p2在主时间轴中,它属于this/_level0/_root吗?

clearInterval()也是一个全局函数,因此只要可以访问间隔的ID(在您的情况下为p2),您就可以从嵌套在任何影片剪辑中的任何其他函数调用它.

所以,如果您有类似的东西:

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

您可以拥有类似的单独功能

function clearP2(){
clearInterval(p2);
}

如果该函数嵌套在某些剪辑中,则您始终可以使用脏的所有_root(如绝对路径中一样)

例如 //clearP2位于远离_root的嵌套剪辑中

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

当然您也可以使用相对路径

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

要记住的想法是确保您可以在需要的地方访问间隔的ID,clearInterval()是全局的

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?

解决方案

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

这篇关于如何在Action Script 2中突破设定间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆