Here are 2 different pieces of code. 1st is the timer code. It's best to use the Timer class for this type of thing. It'll track time properly. 2nd is the formatting code. I added it just for convenience. Do you need any further help to transform this to what you want? You'll mainly need to start/stop the timer based upon myTimer.currentCount. That count is for seconds.
Code://Timer code: var myTimer:Timer = new Timer(1000); myTimer.addEventListener(TimerEvent.TIMER, timerListener); function timerListener(e:TimerEvent):void { time.text = formatTime(myTimer.currentCount); } myTimer.start(); //Formatting code: function formatTime(input:int):String { var hrs:String = (input > 3600 ? Math.floor(input / 3600) + ':' : ''); var mins:String = (hrs && input % 3600 < 600 ? '0' : '') + Math.floor(input % 3600 / 60) + ':'; var secs:String = (input % 60 < 10 ? '0' : '') + input % 60; return hrs + mins + secs; }




Reply With Quote