然后,您可能可以创建一个 SingletonEventDispatcher
并在所有类中使用它来调度事件。
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);
...
}