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

网站建设 2021-07-03 14:34www.dzhlxh.cn网站建设

复制代码
代码如下:

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

Copyright © 2016-2025 www.dzhlxh.cn 金源码 版权所有 Power by

网站模板下载|网络推广|微博营销|seo优化|视频营销|网络营销|微信营销|网站建设|织梦模板|小程序模板