Flash / Flex / ActionScript/Animation/Timer Event — различия между версиями

Материал из Web эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 09:19, 26 мая 2010

add the start() method to our program, things start happening:

 
package {
    import flash.display.Sprite;
    import flash.utils.*;
    import flash.events.*;
    public class Main extends Sprite {
        public static const TIMER_DELAY:Number = 1 * 1000;
        public var timer:Timer = new Timer(TIMER_DELAY, 10);
        public function Main() {
            timer.addEventListener(TimerEvent.TIMER, onTimer);
            timer.addEventListener(TimerEvent.TIMER_COMPLETE,  onTimerComplete);
            timer.start();
        }
        private function onTimer(event:TimerEvent):void {
            trace("Tick.");
        }
        private function onTimerComplete(event:TimerEvent):void {
            trace("Ding!");
        }
    }
}



A timer that has just five intervals:

 
package{
  import flash.display.Sprite;
  import flash.utils.*;
  import flash.events.*;
  
  public class Main extends Sprite{
    public function Main(){
        var timer:Timer = new Timer(1000, 5);
    }
  }
}



Listening for Timer Events

 
package {
    import flash.display.Sprite;
    import flash.utils.*;
    import flash.events.*;
    public class Main extends Sprite {
        public static const TIMER_DELAY:Number = 1 * 1000;
        public var timer:Timer = new Timer(TIMER_DELAY, 10);
        public function Main() {
            timer.addEventListener(TimerEvent.TIMER, onTimer);
            timer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
        }
        private function onTimer(event:TimerEvent):void {
            trace("Tick.");
        }
        private function onTimerComplete(event:TimerEvent):void {
            trace("Ding!");
        }
    }
}



Using Timers

 
package{
  import flash.display.Sprite;
  import flash.utils.*;
  import flash.events.*;
  public class Main extends Sprite{
    public function Main(){
        var timer:Timer = new Timer(1000);
        timer.addEventListener(TimerEvent.TIMER, onTimer);
        
        timer.start(  );
    }
    function onTimer(event:TimerEvent):void {
      trace("on timer");
    }
  }
}