EventDispatcher

Kind of class:class
Inherits from:CoreObject
Implements:
Known subclasses:
Version:07/12/07
Author:Aaron Clinger, Mike Creighton
Classpath:org.casaframework.event.EventDispatcher
File last modified:Sunday, 19 August 2007, 13:43:27
Provides event notification and listener management capabilities to objects.

Advantages of using this EventDispatcher:
  • Ability to remap event handlers to a function not sharing the same name as the event.
  • Ability to remove all event observers for a specified event.
  • Ability to remove all event observers for a specified scope.
  • Ability to remove all event observers subscribed to broadcasting object.

Constructor

EventDispatcher

function EventDispatcher ()

Instance methods

addEventObserver

function addEventObserver (scope:Object, eventName:String, eventHandler:String) : Boolean
Registers a function to receive notification when a event handler is invoked.
#
Parameters:
scope :
The target or object in which to subscribe.
#
eventName :
Event name to subscribe to.
#
eventHandler:
[optional] Name of function to recieve the event. If undefined class assumes eventHandler matches eventName.
#
Returns:
Returns true if the observer was established successfully; otherwise false.
#
Example:
this.eventButton_mc.addEventObserver(this, "onRollOver");

destroy

function destroy () : Void
Removes any internal variables, intervals, enter frames, internal MovieClips and event observers to allow the object to be garbage collected.

Always call destroy() before deleting last object pointer.
#

dispatchEvent

function dispatchEvent (eventName:String) : Boolean
Reports event to all subscribed objects.
#
Parameters:
eventName:
Event name.
#
param(s) :
[optional] Parameters passed to the function specified by "eventName". Multiple parameters are allowed and should be separated by commas: param1,param2, ...,paramN
#
Returns:
Returns true if observer(s) listening to specifed event were found; otherwise false.
#
Example:
this.dispatchEvent("onRelease", 5, true, "Aaron");

removeAllEventObservers

function removeAllEventObservers () : Boolean
Removes all observers regardless of scope or event.
#
Returns:
Returns true if observers were successfully removed; otherwise false.
#

removeEventObserver

function removeEventObserver (scope:Object, eventName:String, eventHandler:String) : Boolean
Removes specific observer for event.
#
Parameters:
scope :
The target or object in which subscribed.
#
eventName :
Event name to unsubscribe to.
#
eventHandler:
[optional] Name of function that recieved the event. If undefined class assumes eventHandler matched eventName.
#
Returns:
Returns true if the observer was successfully found and removed; otherwise false.
#
Example:
this.eventButton_mc.removeEventObserver(this, "onRollOver");

removeEventObserversForEvent

function removeEventObserversForEvent (eventName:String) : Boolean
Removes all observers for a specified event.
#
Parameters:
eventName:
Event name to unsubscribe to.
#
Returns:
Returns true if observers were successfully found for specified eventName and removed; otherwise false.
#
Example:
this.eventButton_mc.removeEventObserversForEvent("onRollOver");

removeEventObserversForScope

function removeEventObserversForScope (scope:Object) : Boolean
Removes all observers in a specified scope.
#
Parameters:
scope:
The target or object in which to unsubscribe.
#
Returns:
Returns true if observers were successfully found in scope and removed; otherwise false.
#
Example:
this.eventButton_mc.removeEventObserversForScope(this);