IDispatchable
A centralized EventDispatcher to decouple event listeners & dispatchers from direct addressing.
Usage: var receiveObj:Object = {_name:"receiveObj"}; // define a generic method for the reciever object to use function onEventReceived (event:Object):Void { var str:String = (this._name + " received Event = { type:" + event.type + ", target:" + event.target + ", data: {"); for (var i in event.data) { str += " " + i + ":" + event.data[i] + ","; } trace (str+" }};"); } // add the method to our reciever object as 'testEvent' receiveObj.testEvent = onEventReceived; // add reciever object as an event listener for "testEvent" Dispatcher.getInstance().addEventListener ("testEvent",receiveObj); // define sender and data objects (optional) var senderObj:Object = this; var dataObj:Object = {message:"hello", someNumber:42}; // Dispatch the event to all 'testEvent' EventListeners Dispatcher.getInstance().dispatchEvent (new Event ("testEvent", senderObj, dataObj));Some excellent explanations of the AS2/3 event models and broadcasters vs dispatchers
public function addEventListener(event:String, handler:Object):Void
Add the event listener to the centralized event manager
event | (String) the name of the event ("click", "change", etc) |
handler | (Object) the function or object that should be called |
Void
public function removeEventListener(event:String, handler:Object):Void
Remove the event listener from the centralized event manager
event | (String) the name of the event ("click", "change", etc) |
handler | (Object) the function or object that should be called |
Void
public function dispatchEvent(e:Event):Void
Dispatch the event to all listeners via the centralized event manager
e | (Event) an Event or one of its subclasses describing the event |
Void
Usage: Dispatcher.getInstance().dispatchEvent(new Event("myEvent", this, {foo:true, bar:false}));
public function bubbleEvent(e:Event):Void
Bubbles event up the chain. The target property is added on the route and then replaced by the new target.
e | (Event) |
Void
public function broadcastEvent(_type:String, _target:Object, _data:Object):Void
Wrapper to dispatchEvent: creates an Event object and dispatchs it to all event listeners
Usage:
Dispatcher.getInstance().broadcastEvent("myEvent",targetObject, {param0:value0, param1:value1, paramn:valuen});
_type | (String) type of event |
_target | (Object) he object that dispatched this event. There is a known bug with this property: It always returns as '/'. This may be a flaw in EventDispatcher; if you need to pass the event source use dispatchEvent. |
_data | (Object) a transport object for any needed data |
Void
public function destroy():Void
Destroy singleton instance.
Void
destroy() in com.sekati.core.CoreInterface