dispatchEvnet(이벤트 직접 전송하기)
EventDispatcher Class 예제 중 임의로 클래스 만들어 사용하기.
package {
import flash.display.Sprite;
import flash.events.Event;
public class EventDispatcherExample extends Sprite {
public function EventDispatcherExample() {
var dispatcher:CustomDispatcher = new CustomDispatcher();
dispatcher.addEventListener(CustomDispatcher.ACTION, actionHandler);
dispatcher.doAction();
}
private function actionHandler(event:Event):void {
trace("actionHandler: " + event);
}
}
}
import flash.events.EventDispatcher;
import flash.events.Event;
class CustomDispatcher extends EventDispatcher {
public static var ACTION:String = "action";
public function doAction():void {
dispatchEvent(new Event(CustomDispatcher.ACTION));
}
}
이벤트 복사해서 사용하기
public function onLoadProgress(event:ProgressEvent):void
{
this.dispatchEvent(event.clone());
}
SoundFacade 예제에서..
public function onPlayTimer(event:TimerEvent):void
{
var estimatedLength:int = Math.ceil(this.s.length / (this.s.bytesLoaded / this.s.bytesTotal));
var progEvent:ProgressEvent = new ProgressEvent(PLAY_PROGRESS, false, false, this.sc.position, estimatedLength);
this.dispatchEvent(progEvent);
}
새로 시작하는 플래시 CS3 에서..
pp.addEventListener(MouseEvent.CLICK, fn);
stage.addEventListener(MouseEvent.CLICK, fnstage);
function fn(e:MouseEvent):void{ trace(e); }
function fnstage(e:MouseEvent):void{ trace(e);}
pp.dispatchEvent (new MouseEvent(MouseEvent.CLICK));

