So i am trying to build a countdown timer (for building a fitness app).
Here is my code for the very basic timer. I'm trying to use getTimer() because the timer class is not accurate at all. I'm trying to start a looping function with a button. And I'm able to make it fire once, but not repeat. This code was modified from something I found online, so if you think I'm totally in the wrong direction please let me know.
Thanks
Code:
var countDownTime:Number = 10;
var startTimeUTC:Number = getTimer() / 1000;
trace(startTimeUTC)
timeText.text = String(countDownTime);
btn1.addEventListener(MouseEvent.CLICK, startTimer);
function startTimer(event:MouseEvent):void
{
var secondsUTC:Number = getTimer() / 1000;
var remainingTime:Number = ((startTimeUTC + countDownTime) - secondsUTC);
if (remainingTime > 0)
{
timeText.text = String(Math.round(remainingTime));
}
else
{
timeText.text = "0"
}
}