-1

嘿,我是 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+"";
    }
4

1 回答 1

0

Timer 功能不是您想要的。那是为了倒计时。您只想计数,这需要在您开始时记录,并从当前运行时中扣除。

import flash.utils.*;
var start:Number = flash.utils.getTimer();

function showElapsedTime():void {
    trace(toTimeCode(flash.utils.getTimer() - start));
}
于 2013-10-29T15:23:05.520 回答