2013-10-29 135 views
-1

嘿,我是新的AC3。遊戲結束後顯示時間as3

這是我的計時器代碼:

它開始在比賽結束幀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

你的代碼似乎沒有任何明顯的錯誤。什麼是問題? – Glitcher

回答

0

定時器功能不是你想要的。這是倒計時。您只需要計數,這需要在開始時進行記錄,並從當前運行時中扣除。

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

function showElapsedTime():void { 
    trace(toTimeCode(flash.utils.getTimer() - start)); 
}