当前位置: 移动技术网 > IT编程>UI设计>设计软件 > AS3 程序延迟执行的方法分享

AS3 程序延迟执行的方法分享

2019年03月21日  | 移动技术网IT编程  | 我要评论

御赐掌柜,节约用水漫画,薛璐 下载


复制代码
代码如下:

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();
}

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网