我想知道您是否可以获得自 ActionScript 计时器启动以来经过的毫秒数。
我想在 flex 中设置一个简单的标签,它的值是计时器(再次)触发之前需要多长时间。
这是代码,在“获取耗时”处,我需要计时器已经运行的时间(自上次触发该函数以来):
var timer = new Timer (10000);
timer.addEventListener(TimerEvent.TIMER, foo);
timer.start();
var numberOfSeconds = timer.delay-timer.'GET ELAPSED TIME';
resetLabel.text = "only "+numberOfSeconds+" until foo fires";
这个获取定时器时间的函数是否存在以及它是如何调用的(谷歌未能回答我)?
最佳答案
没有任何属性可以获取计时器
的剩余时间。解决方法可能是在您的 foo 函数中添加检查。基本设置如下所示:
var realDelay:int = 10000;
var timer:Timer = new Timer (1);
timer.addEventListener(TimerEvent.TIMER, foo);
timer.start();
function foo(e:TimerEvent) : void
{
var realCount:int = Math.floor(timer.currentCount/realDelay);
var timeLeft:Number = (realDelay-timer.currentCount%realDelay);
resetLabel.text = "Real count: " + realCount + ", milliseconds left: " + timeLeft;
}
关于actionscript-3 - 获取计时器耗时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9412064/