그러면 아마도 싱글 톤 EventDispatcher
을 만들고 그것을 모든 클래스에서 사용하여 이벤트를 전달할 수 있습니다.
package <WHATEVER>
{
import flash.events.*;
public class SingletonDispatcher extends EventDispatcher {
private static var dispatcher:SingletonDispatcher = null;
public function SingletonDispatcher (enforcer:SingletonEnforcer) : void {
if (!enforcer) {
throw new Error("Direct instatiation is not allowed");
}
return;
}// end function
public static function GetInstance() : SingletonDispatcher {
if (!dispatcher) {
dispatcher= new SingletonDispatcher (new SingletonEnforcer());
}// end if
return dispatcher;
}// end function
}
}
class SingletonEnforcer {}
그런 다음 당신이 좋아하는 모든 클래스에서 사용할 수 있습니다
public class C {
...
SingletonDispatcher.GetInstance().dispatchEvent(new SomeEvent()); // instead of this.dispatchEvent
...
}
그리고 클래스 A
에,들을 수 있습니다 :
public class A {
...
SingletonDispatcher.GetInstance().addEventListener(SomeEvent.UNREACHABLE_EVENT, thankGod);
...
}
감사합니다. – phil