嘿,我是ac3的新人。
这是我的计时器代码:
从第1帧开始 在比赛结束时,它将继续第3帧。
我不知道如何在那里展示计时器......
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 minutes:String = String(time.minutes);
var seconds:String = String(time.seconds);
var miliseconds:String = String(Math.round(time.milliseconds)/100);
//add zero if neccecary, for example: 2:3.5 becomes 02:03.5
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 = minutes + ":" + seconds+"";
}
答案 0 :(得分:0)
定时器功能不是你想要的。这是倒计时。您只想计算,这需要在开始时进行记录,并从当前运行时中扣除。
import flash.utils.*;
var start:Number = flash.utils.getTimer();
function showElapsedTime():void {
trace(toTimeCode(flash.utils.getTimer() - start));
}