actionscript 3 - Action Script 3. Timer MM:SS doesn't work -
i'm creating app , need show game time mm:ss format. don't know why timer doesn't wrok shows 0:00.359 (359 of miliseconds) , not change. problem? can't find it. thank you.
var timer:timer; //import flash.utils.timer; var txttime:textfield; var tmptime:number; //this store time when game started //your constructor: public function memorygame() { timer = new timer(1000); //create new timer ticks every second. timer.addeventlistener(timerevent.timer, tick, false, 0, true); //listen timer tick txttime = new textfield(); addchild(txttime); tmptime = flash.utils.gettimer(); timer.start(); //start timer //....the rest of code } private function tick(e:event):void { txttime.text = showtimepassed(flash.utils.gettimer() - tmptime); } //this function format time stopwatch function showtimepassed(starttime:int):string { var leadingzeroms:string = ""; //how many leading 0's put in front of miliseconds var leadingzeros:string = ""; //how many leading 0's put in front of seconds var time = gettimer() - starttime; //this gets amount of miliseconds elapsed var miliseconds = (time % 1000); // modulus (%) gives remainder after dividing, if (miliseconds < 10) { //if less 2 digits, add leading 0 leadingzeroms = "0"; } var seconds = math.floor((time / 1000) % 60); //this gets amount of seconds if (seconds < 10) { //if seconds less 2 digits, add leading 0 leadingzeros = "0"; } var minutes = math.floor( (time / (60 * 1000) ) ); //60 seconds times 1000 miliseocnds gets minutes return minutes + ":" + leadingzeros + seconds + "." + leadingzeroms + miliseconds; } //in you-win block of code: var score = flash.utils.gettimer() - tmptime; //this store how many milliseconds took them complete game.
try
timer.currentcount
instead of
flash.utils.gettimer()
it return number of times timer has fired timer-event.
Comments
Post a Comment