次に、おそらく、シングルトン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);
...
}