최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday

티스토리 뷰

방법1) 이벤트객체의 타입을 발생시켜서 전파

 

Main.as


package
{
 import MyDispatch;
 import flash.display.Sprite;
 import flash.events.Event;
 
 public class Main extends Sprite
 {
  private var _myDispatch:MyDispatch;

  public function Main(){
   init();
  }
  
  private function init():void{
   _myDispatch = new MyDispatch();
   
   //Event객체를 통한 Event.COMPLETE 수신
   _myDispatch.addEventListener(Event.COMPLETE, loadComplete);
   _myDispatch.init();
  }

  private function loadComplete(e:Event):void{
   trace("next someThing")
  }
 }
}


MyDispatch.as


package 
{
 import flash.events.Event;
 import flash.events.EventDispatcher;

 //MyDispatch는 EventDispatcher를 상속
 public class MyDispatch extends EventDispatcher
 {
  public function MyDispatch(){
  }
  
  public function init():void{
   //Event 객체의 Event.COMPLETE 전파
   this.dispatchEvent(new Event(Event.COMPLETE));
  }
 }
}

 




방법2) 이벤트상수를 만들어서 전파

 

Main.as


package
{
 import MyDispatch;
 import flash.display.Sprite;
 import flash.events.Event;
 
 public class Main extends Sprite
 {
  private var _myDispatch:MyDispatch;

  public function Main(){
   init();
  }
  
  private function init():void{
   _myDispatch = new MyDispatch();
   
   //Event객체를 통한 Event.COMPLETE 수신
   _myDispatch.addEventListener(MyDispatch.LOAD_COMPLETE, loadComplete);
   _myDispatch.init();
  }

  private function loadComplete(e:Event):void{
   trace("next someThing")
  }
 }
}

MyDispatch.as


package 
{
 import flash.events.Event;
 import flash.events.EventDispatcher;

 //MyDispatch는 EventDispatcher를 상속
 public class MyDispatch extends EventDispatcher
 {
  public static const LOAD_COMPLETE:String = "load_complete";
  
  public function MyDispatch()
  {
  }

  public function init():void
  {
   //EventDispatcher를 상속한 MyDispatch객체의 이벤트전파
   this.dispatchEvent(new Event(LOAD_COMPLETE));
  }
 }
}


댓글