as3 callback function 2

Adobe Flash/ActionScript 3.0 2011. 5. 12. 11:25
반응형


package {
 import flash.display.Sprite;

 /**
  * @author Jang sang wook ( smilejsu@nate.com )
  * @version 1.0
  * @date 2011. 5. 12.
  */
 public class Main extends Sprite {
  
  private var _sample:Sample;
  
  public function Main() {
   _sample = new Sample();
   this.addChild(_sample);
   _sample.callback = fn;
  }
  
  private function fn($str:String):void{
   trace($str);
  }
  
 }//class
}//package


package {
 import flash.display.Sprite;
 import flash.events.MouseEvent;

 /**
  * @author Jang sang wook ( smilejsu@nate.com )
  * @version 1.0
  * @date 2011. 5. 12.
  */
 public class Sample extends Sprite {
  
  private var _callback:Function;
  
  public function Sample() {
   this.graphics.beginFill(Math.random() * 1000000);
   this.graphics.drawCircle(275, 200, 100);
   this.graphics.endFill();
   this.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
  }

  private function mouseDownHandler(event : MouseEvent) : void {
   _callback("click");
  }
  
//  public function get callback() : Function {
//   return _callback;
//  }

  public function set callback(callback : Function) : void {
   _callback = callback;
  }
  
 }//class
}//package

반응형

'Adobe Flash > ActionScript 3.0' 카테고리의 다른 글

Flash custom component  (0) 2011.05.18
Tile Base Game  (0) 2011.05.17
as3 callback function 1  (0) 2011.05.12
Flash CS5 Code Hint for Mac  (0) 2011.04.19
SWC + FDT4 = SWF  (0) 2011.03.10
: