我想用actionscript在flash中創建一個timeup計數器。分/秒顯示良好,但問題是,時間從1開始,而不是0。這驗證碼:Actionscript 3.0:奇怪的默認時間
import flash.utils.Timer;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.globalization.DateTimeFormatter;
var timer:Timer = new Timer(100);
timer.start();
timer.addEventListener(TimerEvent.TIMER, timerTickHandler);
var timerCount:int = 0;
function timerTickHandler(Event:TimerEvent):void
{
timerCount += 100;
toTimeCode(timerCount);
}
function toTimeCode(milliseconds:int) : void {
//create a date object using the elapsed milliseconds
var time:Date = new Date(milliseconds);
//define minutes/seconds/mseconds
var hours:String = String(time.hours);
var minutes:String = String(time.minutes);
var seconds:String = String(time.seconds);
//add zero if neccecary, for example: 2:3.5 becomes 02:03.5
hours = (hours.length != 2) ? '0'+hours : hours;
minutes = (minutes.length != 2) ? '0'+minutes : minutes;
seconds = (seconds.length != 2) ? '0'+seconds : seconds;
//display elapsed time on in a textfield on stage
timer_txt.text = hours + ":" + minutes + ":" + seconds;
}
我什麼都試過,但仍然有使用時間= 1計數器開始時!
該代碼似乎對我來說正常工作。 1停留,還是暫時在那裏?你有沒有試過看看有什麼「痕跡(小時)」出來? – 2013-03-23 23:39:40
小時從值1開始,下一個值是2,3,4,5 ...所以問題只是初始值。 – Nathan 2013-03-24 09:33:28