I made a ten minute timer that starts at 600 and counts down to zero. It displays the current count in a textfield called “textfield_time”. Here’s what it looks like:
var timer:Timer = new Timer(1000, 600);
timer.addEventListener(TimerEvent.TIMER, countdown);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, termin);
timer.start();
textfield_time.text ="600";
function countdown(event:TimerEvent) {
if(timer.currentCount<21){
textfield_time.text ="" +String(600 - timer.currentCount);
}
else{
textfield_time.text ="" +String(600 - timer.currentCount);
}
}
function termin(event:TimerEvent) {
textfield_time.text="0";
}
So far so good. Now, I have a time pickup that floats across the screen now and then. When your avatar makes contact with it, you get extra time - say 15 seconds. I already have working code that detects the collision of the avatar and the pickup, but I can’t figure out how to add functionality to reset the timer to give an additional 15 seconds. I tried:
timer+=15;
which doesn’t work. But you already knew that (hey, I’m new at this!). Any ideas? Maybe some way to get the currentCount value, increment it by 15 seconds, then update the timer value with it?