MACROMEDIA FLEX 2-MIGRATING APPLICATIONS TO FLEX 2 Manuel d'utilisateur Page 182

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 184
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 181
182 Migration Patterns
Using Timer
The setInterval() and clearInterval() methods were deprecated in favor of the Timer
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
start() method to start it.
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
null allows it to be garbage collected.
<?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() method rather than the stop() method to stop the timer. The
difference between
stop() and reset() is that stop() stops the timer but does not reset its
count, while
reset() both stops and resets.
Vue de la page 181
1 2 ... 177 178 179 180 181 182 183 184

Commentaires sur ces manuels

Pas de commentaire