不同的计时器,以毫秒为单位

时间:2014-03-21 21:35:52

标签: actionscript-3

由于我是AS3中的新手,我有倒数计时器,显示单个数字“10”秒,但我的客户希望他们显示像10:00(4位),毫秒。

[更新] http://magnixsolutions.com/clients/OT/9995MB-Scoreboard-NCR-728x90.swf - 现在倒计时显示为09.32:93然后08:34然后07:34:91倒退,当它倒计时发泡,然后停止到00:00。它应该显示4位数。

继承我的代码,显示在“10”秒[更新]

import flash.text.TextField;

var fullTime:int = 10000; // 10 seconds
var updateRate:int = 25; // 60 fps update rate
var myTimer:Timer = new Timer(1000 / updateRate, fullTime / 1000 * updateRate);
var time_txt:TextField = new TextField();
myTimer.start();

myTimer.addEventListener(TimerEvent.TIMER, countdown);

function countdown(e:TimerEvent):void {
    var dt = myTimer.delay * myTimer.repeatCount - myTimer.currentCount * myTimer.delay;
    var seconds = dt / 1000;
    var ms = (dt % 1000) * 0.1; //chop to hundredths
    timer_txt.text = ((seconds < 10) ? "0" + seconds : seconds) + ":" + ((ms < 10) ? "0" +  ms : ms); //format
}

1 个答案:

答案 0 :(得分:1)

代码中的大多数评论。随意更改fps更新速率,如果您有25 fps闪存应用程序,则60 fps更新率没有任何意义。

var fullTime:int = 10000; //10 seconds
var updateRate:int = 60; //60 fps update rate
var myTimer:Timer = new Timer(1000 / updateRate, fullTime / 1000 * updateRate);
var dt:Number, seconds:int, ms:int;

var timer_txt:TextField = new TextField();
myTimer.start();

myTimer.addEventListener(TimerEvent.TIMER, countdown);

function countdown(e:TimerEvent):void {
    dt = myTimer.delay * myTimer.repeatCount - myTimer.currentCount * myTimer.delay;
    seconds = dt / 1000;
    ms = (dt % 1000) * 0.1; //chop to hundredths
    timer_txt.text = ((seconds < 10) ? "0" + seconds : seconds) + ":" + ((ms < 10) ? "0" + ms : ms); //format
}