actionscript 3 - how to convert seconds to minutes:seconds in as3 -



actionscript 3 - how to convert seconds to minutes:seconds in as3 -

hi new in action script 3 in flash cs6 im creating game timer

i want create seconds minutes:seconds format

example:

120 seconds 2:00

this code:

var countdowndec:number = 1; var totalsecs = 120; var countdownsecs = totalsecs; counter.text = countdownsecs; var time:timer = new timer(countdowndec*1000); time.addeventlistener(timerevent.timer, tick); time.reset(); countdownsecs = totalsecs; counter.text = countdownsecs; time.start(); var framelbl:framelabel; function tick(e:timerevent):void { time.start(); if(countdownsecs == 0){ time.stop(); countdownsecs = totalsecs; gotoandplay('timesup'); timesup.play(); } else{ countdownsecs = countdownsecs - countdowndec; counter.text = countdownsecs; } }

please help me problem

divide 60 , round downwards minutes, modulo (%) 60 seconds

var totalsecs = 120; var minutes = math.floor(totalsecs / 60); var seconds = totalsecs % 60; var timeinminutesseconds = minutes + ":" + seconds;

edit:

try this:

var countdowndec:number = 1; var totalsecs:int = 120; var countdownsecs:int = totalsecs; counter.text = getcountdownsecstext(countdownsecs); var time:timer = new timer(countdowndec*1000); time.addeventlistener(timerevent.timer, tick); var framelbl:framelabel; function tick(e:timerevent):void { if(countdownsecs == 0) { time.stop(); countdownsecs = totalsecs; gotoandplay('timesup'); timesup.play(); } else { countdownsecs = countdownsecs - countdowndec; counter.text = getcountdownsecstext(countdownsecs); } } private function getcountdownsecstext(currentamountsecs:int):string{ var minutes:int = math.floor(currentamountsecs / 60); var seconds:int = currentamountsecs % 60; var prependstring:string = ""; if( minutes > 9 ) { prependstring = "0"; } homecoming prependstring + minutes + ":" + seconds; }

actionscript-3 flash-cs6

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -