Actionscript 3 how to track elapsed time?

im new for actionscript3 flash scripts. I have an int variable and I want to add +2 every second since the start of the game. How can i do this? How to find out how much time has passed? thanks in advance!

+6
flash actionscript-3 timer
source share
3 answers

getTimer () will return int exactly how many milliseconds since the start of flash memory.

import flash.utils.getTimer; var myInt:int = getTimer() * 0.001; 

Now myInt will execute for many seconds until the program is running.

edit: oh, to determine how much time has passed, just save the initial myInt and check it for the current timer.

therefore, when the game begins.

 var startTime:int = getTimer(); 

then every frame or whenever you need to check it.

 var currentTime:int = getTimer(); var timeRunning:int = (currentTime - startTime) * 0.001; // this is how many seconds the game has been running. 
+19
source share
 var a:int = 0; var onTimer:Function = function (e:TimerEvent):void { a += 2; } var timer:Timer = new Timer(1000); timer.addEventListener(TimerEvent.TIMER, onTimer); timer.start(); 
+1
source share
 var countdown:Timer = new Timer(1000); countdown.addEventListener(TimerEvent.TIMER, timerHandler); countdown.start(); function timerHandler(e:TimerEvent):void { var minute = Math.floor(countdown.currentCount / 60); if(minute < 10) minute = '0'+minute; var second = countdown.currentCount % 60; if(second < 10) second = '0'+second; var timeElapsed = minute +':'+second; trace(timeElapsed); } 
0
source share

All Articles