2004/10/01 | [教程]函数定时执行
类别(我闪推荐) | 评论(0) | 阅读(82) | 发表于 20:36
Dimitrios扩展了的Function类,版本AS1,代码如下:
// Function callAfter
// by Dimitrios Bendilas (d.bendilas@zefxis.gr)
Function.prototype.callAfter = function(_lag:Number, _parameters:Array) {
   var sTime = getTimer();
   var _function = this;
   var timer = setInterval(function () {
      if (getTimer()-sTime>=_lag) {
          _function.apply(null, _parameters);
          clearInterval(timer);
      }
   }, 50, this);
};
用法:
function traceData(name:String, age:Number) {
   trace(name+", age "+age);
}
traceData.callAfter(2000, ["John", 25]);// 2000 milliseconds

(出自Jiagao

0

评论Comments