1 回答

TA贡献1821条经验 获得超4个赞
可以写和通用运行类~我自己写了个通用的运行函数放到我自己的工具类里(我的是基于Timer)我把代码贴出来分享下~怎么用就自己参透下~
public static function runByTimes(fun,comFun,delay,times):Timer
{
var time:Timer=new Timer(delay,times);
time.addEventListener(TimerEvent.TIMER,timeEnd);
time.addEventListener(TimerEvent.TIMER_COMPLETE,timeStop);
function timeEnd(e:TimerEvent)
{
fun();
}
function timeStop(e:TimerEvent)
{
comFun();
}
time.start();
return time;
}
public static function runByBoolean(fun,bfun,comFun,delay):Timer
{
var time:Timer=new Timer(delay,1000000);
time.addEventListener(TimerEvent.TIMER,timeEnd);
function timeEnd(e:TimerEvent)
{
if(bfun())
{
try{
fun();
}
catch(e:Error){}
}
else
{
comFun()
time.stop();
}
}
time.start();
return time;
}
以上两个函数有不同的功能,第一个是指定调用次数,第二个是指定停止的规则(我定义为一个函数)
添加回答
举报