首页 > 设计 > 详细

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

时间:2016-02-08 22:17:05      阅读:163      评论:0      收藏:0      [点我收藏+]

复制代码
代码如下:

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

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

原文:http://www.jb51.net/flash/actionscript/35365.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!