AS3 程序延迟执行的方法分享_Flash教程-查字典教程网
AS3 程序延迟执行的方法分享
AS3 程序延迟执行的方法分享
发布时间:2016-12-21 来源:查字典编辑
摘要:复制代码代码如下:importflash.events.TimerEvent;importflash.utils.Timer;/***del...

复制代码代码如下:

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

}

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新Flash教程学习
    热门Flash教程学习
    网页设计子分类