AS3 程序延迟执行的方法分享
程序员文章站
2022-04-28 10:50:44
AS3 程序延迟执行的方法分享,需要的朋友可以参考下。... 11-04-21...
复制代码
代码如下:import flash.events.timerevent;
import flash.utils.timer;
/**
* delay function
* a quick and easy delay function that can call a function with parameters. configurable
* with delay time and repeat frequency
*
* @param func:function the function to call when timer is complete
* @param params:array an array of parameters to pass to the function
* @param delay:int [optional] the number of milliseconds to wait before running the function
* @param repeat:int [optional] the number of times the function should repeat
*/
private function delay(func:function, params:array, delay:int = 350, repeat:int = 1):void
{
var f:function;
var timer:timer = new timer(delay, repeat);
timer.addeventlistener(timerevent.timer, f = function():void
{
func.apply(null, params);
if (timer.currentcount == repeat)
{
timer.removeeventlistener(timerevent.timer, f);
timer = null;
}
});
timer.start();
}
上一篇: django-4-模板标签,模板继承
下一篇: Python-接口自动化(二)