PDA

View Full Version : Timer Reset()


dbedient
06-02-2007, 03:12 AM
For the life of me I cannot figure out what is wrong. Obviously I don't know what I'm doing. Here's the code -

public function init() {
// creates a new five-second Timer
var minuteTimer:Timer = new Timer(1000, 5);

// designates listeners for the interval and completion events
minuteTimer.addEventListener(TimerEvent.TIMER, onTick);
minuteTimer.addEventListener(TimerEvent.TIMER_COMP LETE, onTimerComplete);

// starts the timer ticking
minuteTimer.start();
}

public function onTick(evt:TimerEvent):void {
trace("tick " + evt.target.currentCount);
}

public function onTimerComplete(evt:TimerEvent):void {
trace("Time's Up!");
X minuteTimer.reset();
X minuteTimer.start();
}

Everything is fine but the reset and restart. Any help would be geatly appreciated.

dr_zeus
06-04-2007, 06:17 PM
Your minuteTimer variable is local to the init function. You cannot access it anywhere else.

Luckily, since the timer is the one firing the TimerEvents, you may access the event's target like this:

public function onTimerComplete(evt:TimerEvent):void
{
trace("Time's Up!");
var minuteTimer:Timer = evt.target as Timer;
minuteTimer.reset();
minuteTimer.start();
}

Mortimer Jazz
06-05-2007, 09:20 AM
You may also wish to read this:
http://www.colettas.org/?p=115

dbedient
06-05-2007, 01:51 PM
Thanks a ton.