getTimer
Timers for games meassure the amount of time the game has lasted. It requires some intermediate calculations.
To obtain the time information we use the flash native function getTimer()
This function measures the time since the Flash player started, which is different from the time since the game started (later).
The function measures time in milliseconds, so we will have to "translate the amount into minutes and seconds divided by a semicolon: the way humans like measuring time.
Obtaining the play-game duration
First you need to get the exact "start of the game play" by placing the running the function getTimer when the user clicks the START button and store in a variable (let's call it startTime).
To get the current time in the game you have to place the current value of getTimer and substratct the amount of time before we began playing (startTime)
var timePassed: int = getTimer - startTime;
.
Showing a digital clock
The value of the variable timePassed contains time meassured in milliseconds.
Those are the steps to convert it into a digital clock format,
1. To compute minutes and seconds:
var seconds: int = Math.floor ( timePassed / 1000)
var minutes: int = Math.floor ( seconds / 60)
seconds -= minutes *60
2. To format minutes and seconds into a clock string:
var timeString: String = minutes + " : " + String (seconds +100). substr (1,2);
timeDisplay.text = timeString