Responding to Event.ACTIVATE and Event.DEACTIVATE : Event « Development « Flash / Flex / ActionScript






Responding to Event.ACTIVATE and Event.DEACTIVATE

 
package {
  import flash.display.*;
  import flash.utils.*;
  import flash.events.*;

  public class Main extends Sprite {
    private var timer:Timer;
    private var rect:Sprite;

    public function Main() {
      rect = new Sprite(  );
      rect.x = 200;
      rect.y = 200;
      rect.graphics.lineStyle(1);
      rect.graphics.beginFill(0x0000FF);
      rect.graphics.drawRect(0, 0, 150, 75);
      addChild(rect);

      addEventListener(Event.ACTIVATE, activateListener);
      addEventListener(Event.DEACTIVATE, deactivateListener);

      timer = new Timer(50, 0);
      timer.addEventListener(TimerEvent.TIMER, timerListener);
    }

    private function timerListener (e:TimerEvent):void {
      rect.rotation += 10;
    }

    private function activateListener (e:Event):void {
      timer.start(  );
    }

    private function deactivateListener (e:Event):void {
      timer.stop(  );
    }
  }
}

        








Related examples in the same category

1.Handling Events: a simple application that draws successive random lines
2.Event Listener Priority
3.Add Event listener
4.Listeners for the Event.RESIZE event must be registered with Flash Player's Stage instance,
5.The Event.MOUSE_LEAVE Event
6.Responding to Event.RESIZE.
7.Preventing Default Event Behavior