Using Timer - Adobe FLEX 2-MIGRATING APPLICATIONS TO FLEX 2 Manual

Migrating applications to flex 2
Table of Contents

Advertisement

Using Timer

The
setInterval()
class. You can still use these methods; they are in the flash.util package.
When you use Timers, keep the following in mind:
When a Timer is first created with the new operator, it is stopped; you must use the
method to start it.
start()
Instances of the Timer class dispatch events that you handle like any other event.
The following example creates and destroys a Timer object each time you click the Start and
Stop buttons. Setting the timer to
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script><![CDATA[
import flash.util.Timer;
import flash.events.TimerEvent;
private var timer:Timer;
private function startTimer():void {
timer = new Timer(1000);
timer.addEventListener(TimerEvent.TIMER, timerHandler);
timer.start();
}
private function stopTimer():void {
timer.stop();
timer = null;
}
private function timerHandler(event:TimerEvent):void {
trace("timer");
}
]]></mx:Script>
<mx:Button label="Start Timer" click="startTimer();"/>
<mx:Button label="Stop Timer" click="stopTimer();"/>
</mx:Application>
You can also use the
reset()
difference between
stop()
count, while
reset()
182
Migration Patterns
and
clearInterval()
allows it to be garbage collected.
null
method rather than the
and
is that
reset()
both stops and resets.
methods were deprecated in favor of the Timer
method to stop the timer. The
stop()
stops the timer but does not reset its
stop()

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex 2

Table of Contents