jeudi 28 mai 2015

How do you collect timer string data in object

I have a simple count-up timer that displays milliseconds, seconds, and minutes in real time. When a certain condition is met the stop timer is triggered. I am confused on how to get that time stored in an object and then displayed by shortest time first.

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 
{
//creating 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+"." + miliseconds;
}

Aucun commentaire:

Enregistrer un commentaire