ActionScript 3 ActionScript 3延迟功能

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 ActionScript 3延迟功能相关的知识,希望对你有一定的参考价值。

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

以上是关于ActionScript 3 ActionScript 3延迟功能的主要内容,如果未能解决你的问题,请参考以下文章

在 JavaScript 和 ActionScript 之间共享数组引用

MXML 和用于移动设备的 ActionScript 之间的真正区别是啥?

ActionScript 3 使用ActionScript 3暂停框架

ActionScript 3 ActionScript 3延迟功能

ActionScript 3 ActionScript 3 SliceBitmap类

ActionScript 3 ActionScript 3中的XML循环