AS3 程序延迟执行的方法分享
admin 2013-03-07 15:58:58
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();
}
IT时代网(关注微信公众号ITtime2000,定时推送,互动有福利惊喜)所有原创文章版权所有,未经授权,转载必究。
创客100创投基金成立于2015年,直通硅谷,专注于TMT领域早期项目投资。LP均来自政府、互联网IT、传媒知名企业和个人。创客100创投基金对IT、通信、互联网、IP等有着自己独特眼光和丰富的资源。决策快、投资快是创客100基金最显著的特点。