A nice simple one to start the day!
I can't use dispatchEvent
in my static class
, I was wondering if anyone knew how I can achieve similar functionality or if it's possible at all to call dispatchEvent from my static class?
I basically want to inform my action script code in my flash file when functionality in my static class is complete.
Thanks,
After reading the answers and gaining an understanding of what I can achieve, I have implemented the following (thought it would help users in the future if they could see some example code).
private static var dispatcher:EventDispatcher = new EventDispatcher();
public static function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void {
dispatcher.addEventListener(type, listener, useCapture, priority, useWeakReference);
}
public static function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void {
dispatcher.removeEventListener(type, listener, useCapture);
}
public static function dispatchEvent(event:Event):Boolean {
return dispatcher.dispatchEvent(event);
}
public static function hasEventListener(type:String):Boolean {
return dispatcher.hasEventListener(type);
}
Static classes (classes with static properties and methods) can't inherit ordinary instance-level methods and can't implement interfaces with static methods. So your public static function dispatchEvent
can't take a part in EventDispatcher
or IEventDispatcher
.
You can create the same static methods as in IEventDispatcher
and then create a static instance of IEventDispatcher
to handle events but your static class itself can't be EventDispatcher
but can only look the similar.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With