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
// 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)