mobile-graphic-easel-src-easeljs-events-EventDispatcher.js / js
The EventDispatcher provides methods for managing prioritized queues of event listeners and dispatching events. All {{#crossLink "DisplayObject"}}{{/crossLink}} classes dispatch events, as well as some of the utilities like {{#crossLink "Ticker"}}{{/crossLink}}. You can either extend this class or mix its methods into an existing prototype or instance by using the EventDispatcher {{#crossLink "EventDispatcher/initialize"}}{{/crossLink}} method. <h4>Example</h4> Add EventDispatcher capabilities to the "MyClass" class. EventDispatcher.initialize(MyClass.prototype); Add an event (see {{#crossLink "EventDispatcher/addEventListener"}}{{/crossLink}}). instance.addEventListener("eventName", handlerMethod); function handlerMethod(event) { console.log(event.target + " Was Clicked"); } <b>Maintaining proper scope</b><br /> When using EventDispatcher in a class, you may need to use <code>Function.bind</code> or another approach to maintain you method scope. Note that Function.bind is not supported in some older browsers. instance.addEventListener("click", handleClick.bind(this)); function handleClick(event) { console.log("Method called in scope: " + this); } Please note that currently, EventDispatcher does not support event priority or bubbling. Future versions may add support for one or both of these features. @class EventDispatcher @constructor
Static initializer to mix in EventDispatcher methods. @method initialize @static
parameter: {Object} target The target object to inject EventDispatcher methods into. This can be an instance or a prototype.
@protected @property _listeners @type Object
Initialization method. @method initialize @protected
Adds the specified event listener. @method addEventListener
parameter: {String} type The string type of the event.
parameter: {Function | Object} listener An object with a handleEvent method, or a function that will be called when the event is dispatched.
returns: {Function | Object} Returns the listener for chaining or assignment.
Removes the specified event listener. @method removeEventListener
parameter: {String} type The string type of the event.
parameter: {Function | Object} listener The listener function or object.
Removes all listeners for the specified type, or all listeners of all types. @method removeAllEventListeners
parameter: {String} [type] The string type of the event. If omitted, all listeners for all types will be removed.
Dispatches the specified event. @method dispatchEvent
parameter: {Object | String} eventObj An object with a "type" property, or a string type. If a string is used, dispatchEvent will construct a generic event object with the specified type.
parameter: {Object} [target] The object to use as the target property of the event object. This will default to the dispatching object.
returns: {Boolean} Returns true if any listener returned true.
Indicates whether there is at least one listener for the specified event type. @method hasEventListener
parameter: {String} type The string type of the event.
returns: {Boolean} Returns true if there is at least one listener for the specified event.
@method toString
returns: {String} a string representation of the instance.
(C) Æliens 04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.