all repos — simplyrpg @ 05a250383b5037effb602fc3ca4d2bb1cdf4da90

Fork of https://github.com/harperd1/simplyRPG — multi-map VTT, token visibility, dark theme, stream HUD

libraries/EaselJS_docs/files/createjs_events_EventDispatcher.js.html (view raw)

  1<!DOCTYPE html>
  2<html lang="en">
  3<head>
  4    <meta charset="utf-8">
  5    <link rel="stylesheet" href="../assets/css/yui-cssgrids-min.css">
  6    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
  7    <link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
  8    <link rel="shortcut icon" type="image/x-icon" href="../assets/favicon.ico">
  9    <script src="../assets/js/yui-source.js"></script>
 10	<title>EaselJS v1.0.0 API Documentation : createjs/events/EventDispatcher.js</title>
 11</head>
 12<body class="yui3-skin-sam">
 13
 14<div id="doc">
 15    <div id="hd" class="yui3-g header">
 16        <div class="yui3-u-3-4">
 17            
 18                <h1><a href="http://www.createjs.com/easeljs"><img src="../assets/docs-icon-EaselJS.png" title="EaselJS"></a></h1>
 19            
 20        </div>
 21        <div class="version">
 22            <em>API Documentation for: 1.0.0</em>
 23        </div>
 24    </div>
 25    <div id="bd" class="yui3-g">
 26
 27        <div class="yui3-u-1-4">
 28            <div id="docs-sidebar" class="sidebar apidocs">
 29                <div id="api-list">
 30    <h2 class="off-left">APIs</h2>
 31    <div id="api-tabview" class="tabview">
 32        <ul class="tabs">
 33            <li><a href="#api-classes">Classes</a></li>
 34        </ul>
 35
 36        <div id="api-tabview-filter">
 37            <input type="search" id="api-filter" placeholder="Type to filter APIs">
 38        </div>
 39
 40        <div id="api-tabview-panel">
 41            <ul id="api-classes" class="apis classes">
 42            
 43                <li><a href="../classes/AlphaMapFilter.html">AlphaMapFilter</a></li>
 44            
 45                <li><a href="../classes/AlphaMaskFilter.html">AlphaMaskFilter</a></li>
 46            
 47                <li><a href="../classes/Bitmap.html">Bitmap</a></li>
 48            
 49                <li><a href="../classes/BitmapCache.html">BitmapCache</a></li>
 50            
 51                <li><a href="../classes/BitmapText.html">BitmapText</a></li>
 52            
 53                <li><a href="../classes/BlurFilter.html">BlurFilter</a></li>
 54            
 55                <li><a href="../classes/ButtonHelper.html">ButtonHelper</a></li>
 56            
 57                <li><a href="../classes/ColorFilter.html">ColorFilter</a></li>
 58            
 59                <li><a href="../classes/ColorMatrix.html">ColorMatrix</a></li>
 60            
 61                <li><a href="../classes/ColorMatrixFilter.html">ColorMatrixFilter</a></li>
 62            
 63                <li><a href="../classes/Container.html">Container</a></li>
 64            
 65                <li><a href="../classes/DisplayObject.html">DisplayObject</a></li>
 66            
 67                <li><a href="../classes/DisplayProps.html">DisplayProps</a></li>
 68            
 69                <li><a href="../classes/DOMElement.html">DOMElement</a></li>
 70            
 71                <li><a href="../classes/EaselJS.html">EaselJS</a></li>
 72            
 73                <li><a href="../classes/Event.html">Event</a></li>
 74            
 75                <li><a href="../classes/EventDispatcher.html">EventDispatcher</a></li>
 76            
 77                <li><a href="../classes/Filter.html">Filter</a></li>
 78            
 79                <li><a href="../classes/Graphics.html">Graphics</a></li>
 80            
 81                <li><a href="../classes/Graphics.Arc.html">Graphics.Arc</a></li>
 82            
 83                <li><a href="../classes/Graphics.ArcTo.html">Graphics.ArcTo</a></li>
 84            
 85                <li><a href="../classes/Graphics.BeginPath.html">Graphics.BeginPath</a></li>
 86            
 87                <li><a href="../classes/Graphics.BezierCurveTo.html">Graphics.BezierCurveTo</a></li>
 88            
 89                <li><a href="../classes/Graphics.Circle.html">Graphics.Circle</a></li>
 90            
 91                <li><a href="../classes/Graphics.ClosePath.html">Graphics.ClosePath</a></li>
 92            
 93                <li><a href="../classes/Graphics.Ellipse.html">Graphics.Ellipse</a></li>
 94            
 95                <li><a href="../classes/Graphics.Fill.html">Graphics.Fill</a></li>
 96            
 97                <li><a href="../classes/Graphics.LineTo.html">Graphics.LineTo</a></li>
 98            
 99                <li><a href="../classes/Graphics.MoveTo.html">Graphics.MoveTo</a></li>
100            
101                <li><a href="../classes/Graphics.PolyStar.html">Graphics.PolyStar</a></li>
102            
103                <li><a href="../classes/Graphics.QuadraticCurveTo.html">Graphics.QuadraticCurveTo</a></li>
104            
105                <li><a href="../classes/Graphics.Rect.html">Graphics.Rect</a></li>
106            
107                <li><a href="../classes/Graphics.RoundRect.html">Graphics.RoundRect</a></li>
108            
109                <li><a href="../classes/Graphics.Stroke.html">Graphics.Stroke</a></li>
110            
111                <li><a href="../classes/Graphics.StrokeDash.html">Graphics.StrokeDash</a></li>
112            
113                <li><a href="../classes/Graphics.StrokeStyle.html">Graphics.StrokeStyle</a></li>
114            
115                <li><a href="../classes/Matrix2D.html">Matrix2D</a></li>
116            
117                <li><a href="../classes/MouseEvent.html">MouseEvent</a></li>
118            
119                <li><a href="../classes/MovieClip.html">MovieClip</a></li>
120            
121                <li><a href="../classes/MovieClipPlugin.html">MovieClipPlugin</a></li>
122            
123                <li><a href="../classes/Point.html">Point</a></li>
124            
125                <li><a href="../classes/Rectangle.html">Rectangle</a></li>
126            
127                <li><a href="../classes/Shadow.html">Shadow</a></li>
128            
129                <li><a href="../classes/Shape.html">Shape</a></li>
130            
131                <li><a href="../classes/Sprite.html">Sprite</a></li>
132            
133                <li><a href="../classes/SpriteSheet.html">SpriteSheet</a></li>
134            
135                <li><a href="../classes/SpriteSheetBuilder.html">SpriteSheetBuilder</a></li>
136            
137                <li><a href="../classes/SpriteSheetUtils.html">SpriteSheetUtils</a></li>
138            
139                <li><a href="../classes/Stage.html">Stage</a></li>
140            
141                <li><a href="../classes/StageGL.html">StageGL</a></li>
142            
143                <li><a href="../classes/Text.html">Text</a></li>
144            
145                <li><a href="../classes/Ticker.html">Ticker</a></li>
146            
147                <li><a href="../classes/Touch.html">Touch</a></li>
148            
149                <li><a href="../classes/UID.html">UID</a></li>
150            
151                <li><a href="../classes/Utility Methods.html">Utility Methods</a></li>
152            
153                <li><a href="../classes/VideoBuffer.html">VideoBuffer</a></li>
154            
155                <li><a href="../classes/WebGLInspector.html">WebGLInspector</a></li>
156            
157            </ul>
158
159            <ul id="api-modules" class="apis modules">
160            
161                <li><a href="../modules/CreateJS.html">CreateJS</a></li>
162            
163                <li><a href="../modules/EaselJS.html">EaselJS</a></li>
164            
165            </ul>
166        </div>
167    </div>
168</div>
169
170            </div>
171        </div>
172        <div class="yui3-u-3-4">
173            <div id="api-options">
174        Show:
175        <label for="api-show-inherited">
176            <input type="checkbox" id="api-show-inherited" checked>
177            Inherited
178        </label>
179
180        <label for="api-show-protected">
181            <input type="checkbox" id="api-show-protected">
182            Protected
183        </label>
184
185        <label for="api-show-private">
186            <input type="checkbox" id="api-show-private">
187            Private
188        </label>
189        <label for="api-show-deprecated">
190            <input type="checkbox" id="api-show-deprecated">
191            Deprecated
192        </label>
193
194    </div>
195            <div class="apidocs">
196                <div id="docs-main">
197                    <div class="content source-content">
198                        <script>
199	var name = createjs/events/EventDispatcher.js      
200</script>
201<h1 class="file-heading">File:EventDispatcher.js</h1>
202
203<div class="file">
204    <pre class="code prettyprint linenums">
205/*
206* EventDispatcher
207* Visit http://createjs.com/ for documentation, updates and examples.
208*
209* Copyright (c) 2010 gskinner.com, inc.
210*
211* Permission is hereby granted, free of charge, to any person
212* obtaining a copy of this software and associated documentation
213* files (the &quot;Software&quot;), to deal in the Software without
214* restriction, including without limitation the rights to use,
215* copy, modify, merge, publish, distribute, sublicense, and/or sell
216* copies of the Software, and to permit persons to whom the
217* Software is furnished to do so, subject to the following
218* conditions:
219*
220* The above copyright notice and this permission notice shall be
221* included in all copies or substantial portions of the Software.
222*
223* THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,
224* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
225* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
226* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
227* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
228* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
229* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
230* OTHER DEALINGS IN THE SOFTWARE.
231*/
232
233/**
234 * @module CreateJS
235 */
236
237// namespace:
238this.createjs = this.createjs||{};
239
240(function() {
241	&quot;use strict&quot;;
242
243
244// constructor:
245	/**
246	 * EventDispatcher provides methods for managing queues of event listeners and dispatching events.
247	 *
248	 * You can either extend EventDispatcher or mix its methods into an existing prototype or instance by using the
249	 * EventDispatcher {{#crossLink &quot;EventDispatcher/initialize&quot;}}{{/crossLink}} method.
250	 * 
251	 * Together with the CreateJS Event class, EventDispatcher provides an extended event model that is based on the
252	 * DOM Level 2 event model, including addEventListener, removeEventListener, and dispatchEvent. It supports
253	 * bubbling / capture, preventDefault, stopPropagation, stopImmediatePropagation, and handleEvent.
254	 * 
255	 * EventDispatcher also exposes a {{#crossLink &quot;EventDispatcher/on&quot;}}{{/crossLink}} method, which makes it easier
256	 * to create scoped listeners, listeners that only run once, and listeners with associated arbitrary data. The 
257	 * {{#crossLink &quot;EventDispatcher/off&quot;}}{{/crossLink}} method is merely an alias to
258	 * {{#crossLink &quot;EventDispatcher/removeEventListener&quot;}}{{/crossLink}}.
259	 * 
260	 * Another addition to the DOM Level 2 model is the {{#crossLink &quot;EventDispatcher/removeAllEventListeners&quot;}}{{/crossLink}}
261	 * method, which can be used to listeners for all events, or listeners for a specific event. The Event object also 
262	 * includes a {{#crossLink &quot;Event/remove&quot;}}{{/crossLink}} method which removes the active listener.
263	 *
264	 * &lt;h4&gt;Example&lt;/h4&gt;
265	 * Add EventDispatcher capabilities to the &quot;MyClass&quot; class.
266	 *
267	 *      EventDispatcher.initialize(MyClass.prototype);
268	 *
269	 * Add an event (see {{#crossLink &quot;EventDispatcher/addEventListener&quot;}}{{/crossLink}}).
270	 *
271	 *      instance.addEventListener(&quot;eventName&quot;, handlerMethod);
272	 *      function handlerMethod(event) {
273	 *          console.log(event.target + &quot; Was Clicked&quot;);
274	 *      }
275	 *
276	 * &lt;b&gt;Maintaining proper scope&lt;/b&gt;&lt;br /&gt;
277	 * Scope (ie. &quot;this&quot;) can be be a challenge with events. Using the {{#crossLink &quot;EventDispatcher/on&quot;}}{{/crossLink}}
278	 * method to subscribe to events simplifies this.
279	 *
280	 *      instance.addEventListener(&quot;click&quot;, function(event) {
281	 *          console.log(instance == this); // false, scope is ambiguous.
282	 *      });
283	 *      
284	 *      instance.on(&quot;click&quot;, function(event) {
285	 *          console.log(instance == this); // true, &quot;on&quot; uses dispatcher scope by default.
286	 *      });
287	 * 
288	 * If you want to use addEventListener instead, you may want to use function.bind() or a similar proxy to manage
289	 * scope.
290	 *
291	 * &lt;b&gt;Browser support&lt;/b&gt;
292	 * The event model in CreateJS can be used separately from the suite in any project, however the inheritance model
293	 * requires modern browsers (IE9+).
294	 *      
295	 *
296	 * @class EventDispatcher
297	 * @constructor
298	 **/
299	function EventDispatcher() {
300	
301	
302	// private properties:
303		/**
304		 * @protected
305		 * @property _listeners
306		 * @type Object
307		 **/
308		this._listeners = null;
309		
310		/**
311		 * @protected
312		 * @property _captureListeners
313		 * @type Object
314		 **/
315		this._captureListeners = null;
316	}
317	var p = EventDispatcher.prototype;
318
319// static public methods:
320	/**
321	 * Static initializer to mix EventDispatcher methods into a target object or prototype.
322	 * 
323	 * 		EventDispatcher.initialize(MyClass.prototype); // add to the prototype of the class
324	 * 		EventDispatcher.initialize(myObject); // add to a specific instance
325	 * 
326	 * @method initialize
327	 * @static
328	 * @param {Object} target The target object to inject EventDispatcher methods into. This can be an instance or a
329	 * prototype.
330	 **/
331	EventDispatcher.initialize = function(target) {
332		target.addEventListener = p.addEventListener;
333		target.on = p.on;
334		target.removeEventListener = target.off =  p.removeEventListener;
335		target.removeAllEventListeners = p.removeAllEventListeners;
336		target.hasEventListener = p.hasEventListener;
337		target.dispatchEvent = p.dispatchEvent;
338		target._dispatchEvent = p._dispatchEvent;
339		target.willTrigger = p.willTrigger;
340	};
341	
342
343// public methods:
344	/**
345	 * Adds the specified event listener. Note that adding multiple listeners to the same function will result in
346	 * multiple callbacks getting fired.
347	 *
348	 * &lt;h4&gt;Example&lt;/h4&gt;
349	 *
350	 *      displayObject.addEventListener(&quot;click&quot;, handleClick);
351	 *      function handleClick(event) {
352	 *         // Click happened.
353	 *      }
354	 *
355	 * @method addEventListener
356	 * @param {String} type The string type of the event.
357	 * @param {Function | Object} listener An object with a handleEvent method, or a function that will be called when
358	 * the event is dispatched.
359	 * @param {Boolean} [useCapture] For events that bubble, indicates whether to listen for the event in the capture or bubbling/target phase.
360	 * @return {Function | Object} Returns the listener for chaining or assignment.
361	 **/
362	p.addEventListener = function(type, listener, useCapture) {
363		var listeners;
364		if (useCapture) {
365			listeners = this._captureListeners = this._captureListeners||{};
366		} else {
367			listeners = this._listeners = this._listeners||{};
368		}
369		var arr = listeners[type];
370		if (arr) { this.removeEventListener(type, listener, useCapture); }
371		arr = listeners[type]; // remove may have deleted the array
372		if (!arr) { listeners[type] = [listener];  }
373		else { arr.push(listener); }
374		return listener;
375	};
376	
377	/**
378	 * A shortcut method for using addEventListener that makes it easier to specify an execution scope, have a listener
379	 * only run once, associate arbitrary data with the listener, and remove the listener.
380	 * 
381	 * This method works by creating an anonymous wrapper function and subscribing it with addEventListener.
382	 * The wrapper function is returned for use with &#x60;removeEventListener&#x60; (or &#x60;off&#x60;).
383	 * 
384	 * &lt;b&gt;IMPORTANT:&lt;/b&gt; To remove a listener added with &#x60;on&#x60;, you must pass in the returned wrapper function as the listener, or use
385	 * {{#crossLink &quot;Event/remove&quot;}}{{/crossLink}}. Likewise, each time you call &#x60;on&#x60; a NEW wrapper function is subscribed, so multiple calls
386	 * to &#x60;on&#x60; with the same params will create multiple listeners.
387	 * 
388	 * &lt;h4&gt;Example&lt;/h4&gt;
389	 * 
390	 * 		var listener = myBtn.on(&quot;click&quot;, handleClick, null, false, {count:3});
391	 * 		function handleClick(evt, data) {
392	 * 			data.count -= 1;
393	 * 			console.log(this == myBtn); // true - scope defaults to the dispatcher
394	 * 			if (data.count == 0) {
395	 * 				alert(&quot;clicked 3 times!&quot;);
396	 * 				myBtn.off(&quot;click&quot;, listener);
397	 * 				// alternately: evt.remove();
398	 * 			}
399	 * 		}
400	 * 
401	 * @method on
402	 * @param {String} type The string type of the event.
403	 * @param {Function | Object} listener An object with a handleEvent method, or a function that will be called when
404	 * the event is dispatched.
405	 * @param {Object} [scope] The scope to execute the listener in. Defaults to the dispatcher/currentTarget for function listeners, and to the listener itself for object listeners (ie. using handleEvent).
406	 * @param {Boolean} [once=false] If true, the listener will remove itself after the first time it is triggered.
407	 * @param {*} [data] Arbitrary data that will be included as the second parameter when the listener is called.
408	 * @param {Boolean} [useCapture=false] For events that bubble, indicates whether to listen for the event in the capture or bubbling/target phase.
409	 * @return {Function} Returns the anonymous function that was created and assigned as the listener. This is needed to remove the listener later using .removeEventListener.
410	 **/
411	p.on = function(type, listener, scope, once, data, useCapture) {
412		if (listener.handleEvent) {
413			scope = scope||listener;
414			listener = listener.handleEvent;
415		}
416		scope = scope||this;
417		return this.addEventListener(type, function(evt) {
418				listener.call(scope, evt, data);
419				once&amp;&amp;evt.remove();
420			}, useCapture);
421	};
422
423	/**
424	 * Removes the specified event listener.
425	 *
426	 * &lt;b&gt;Important Note:&lt;/b&gt; that you must pass the exact function reference used when the event was added. If a proxy
427	 * function, or function closure is used as the callback, the proxy/closure reference must be used - a new proxy or
428	 * closure will not work.
429	 *
430	 * &lt;h4&gt;Example&lt;/h4&gt;
431	 *
432	 *      displayObject.removeEventListener(&quot;click&quot;, handleClick);
433	 *
434	 * @method removeEventListener
435	 * @param {String} type The string type of the event.
436	 * @param {Function | Object} listener The listener function or object.
437	 * @param {Boolean} [useCapture] For events that bubble, indicates whether to listen for the event in the capture or bubbling/target phase.
438	 **/
439	p.removeEventListener = function(type, listener, useCapture) {
440		var listeners = useCapture ? this._captureListeners : this._listeners;
441		if (!listeners) { return; }
442		var arr = listeners[type];
443		if (!arr) { return; }
444		for (var i=0,l=arr.length; i&lt;l; i++) {
445			if (arr[i] == listener) {
446				if (l==1) { delete(listeners[type]); } // allows for faster checks.
447				else { arr.splice(i,1); }
448				break;
449			}
450		}
451	};
452	
453	/**
454	 * A shortcut to the removeEventListener method, with the same parameters and return value. This is a companion to the
455	 * .on method.
456	 * 
457	 * &lt;b&gt;IMPORTANT:&lt;/b&gt; To remove a listener added with &#x60;on&#x60;, you must pass in the returned wrapper function as the listener. See 
458	 * {{#crossLink &quot;EventDispatcher/on&quot;}}{{/crossLink}} for an example.
459	 *
460	 * @method off
461	 * @param {String} type The string type of the event.
462	 * @param {Function | Object} listener The listener function or object.
463	 * @param {Boolean} [useCapture] For events that bubble, indicates whether to listen for the event in the capture or bubbling/target phase.
464	 **/
465	p.off = p.removeEventListener;
466
467	/**
468	 * Removes all listeners for the specified type, or all listeners of all types.
469	 *
470	 * &lt;h4&gt;Example&lt;/h4&gt;
471	 *
472	 *      // Remove all listeners
473	 *      displayObject.removeAllEventListeners();
474	 *
475	 *      // Remove all click listeners
476	 *      displayObject.removeAllEventListeners(&quot;click&quot;);
477	 *
478	 * @method removeAllEventListeners
479	 * @param {String} [type] The string type of the event. If omitted, all listeners for all types will be removed.
480	 **/
481	p.removeAllEventListeners = function(type) {
482		if (!type) { this._listeners = this._captureListeners = null; }
483		else {
484			if (this._listeners) { delete(this._listeners[type]); }
485			if (this._captureListeners) { delete(this._captureListeners[type]); }
486		}
487	};
488
489	/**
490	 * Dispatches the specified event to all listeners.
491	 *
492	 * &lt;h4&gt;Example&lt;/h4&gt;
493	 *
494	 *      // Use a string event
495	 *      this.dispatchEvent(&quot;complete&quot;);
496	 *
497	 *      // Use an Event instance
498	 *      var event = new createjs.Event(&quot;progress&quot;);
499	 *      this.dispatchEvent(event);
500	 *
501	 * @method dispatchEvent
502	 * @param {Object | String | Event} eventObj An object with a &quot;type&quot; property, or a string type.
503	 * While a generic object will work, it is recommended to use a CreateJS Event instance. If a string is used,
504	 * dispatchEvent will construct an Event instance if necessary with the specified type. This latter approach can
505	 * be used to avoid event object instantiation for non-bubbling events that may not have any listeners.
506	 * @param {Boolean} [bubbles] Specifies the &#x60;bubbles&#x60; value when a string was passed to eventObj.
507	 * @param {Boolean} [cancelable] Specifies the &#x60;cancelable&#x60; value when a string was passed to eventObj.
508	 * @return {Boolean} Returns false if &#x60;preventDefault()&#x60; was called on a cancelable event, true otherwise.
509	 **/
510	p.dispatchEvent = function(eventObj, bubbles, cancelable) {
511		if (typeof eventObj == &quot;string&quot;) {
512			// skip everything if there&#x27;s no listeners and it doesn&#x27;t bubble:
513			var listeners = this._listeners;
514			if (!bubbles &amp;&amp; (!listeners || !listeners[eventObj])) { return true; }
515			eventObj = new createjs.Event(eventObj, bubbles, cancelable);
516		} else if (eventObj.target &amp;&amp; eventObj.clone) {
517			// redispatching an active event object, so clone it:
518			eventObj = eventObj.clone();
519		}
520		
521		// TODO: it would be nice to eliminate this. Maybe in favour of evtObj instanceof Event? Or !!evtObj.createEvent
522		try { eventObj.target = this; } catch (e) {} // try/catch allows redispatching of native events
523
524		if (!eventObj.bubbles || !this.parent) {
525			this._dispatchEvent(eventObj, 2);
526		} else {
527			var top=this, list=[top];
528			while (top.parent) { list.push(top = top.parent); }
529			var i, l=list.length;
530
531			// capture &amp; atTarget
532			for (i=l-1; i&gt;=0 &amp;&amp; !eventObj.propagationStopped; i--) {
533				list[i]._dispatchEvent(eventObj, 1+(i==0));
534			}
535			// bubbling
536			for (i=1; i&lt;l &amp;&amp; !eventObj.propagationStopped; i++) {
537				list[i]._dispatchEvent(eventObj, 3);
538			}
539		}
540		return !eventObj.defaultPrevented;
541	};
542
543	/**
544	 * Indicates whether there is at least one listener for the specified event type.
545	 * @method hasEventListener
546	 * @param {String} type The string type of the event.
547	 * @return {Boolean} Returns true if there is at least one listener for the specified event.
548	 **/
549	p.hasEventListener = function(type) {
550		var listeners = this._listeners, captureListeners = this._captureListeners;
551		return !!((listeners &amp;&amp; listeners[type]) || (captureListeners &amp;&amp; captureListeners[type]));
552	};
553	
554	/**
555	 * Indicates whether there is at least one listener for the specified event type on this object or any of its
556	 * ancestors (parent, parent&#x27;s parent, etc). A return value of true indicates that if a bubbling event of the
557	 * specified type is dispatched from this object, it will trigger at least one listener.
558	 * 
559	 * This is similar to {{#crossLink &quot;EventDispatcher/hasEventListener&quot;}}{{/crossLink}}, but it searches the entire
560	 * event flow for a listener, not just this object.
561	 * @method willTrigger
562	 * @param {String} type The string type of the event.
563	 * @return {Boolean} Returns &#x60;true&#x60; if there is at least one listener for the specified event.
564	 **/
565	p.willTrigger = function(type) {
566		var o = this;
567		while (o) {
568			if (o.hasEventListener(type)) { return true; }
569			o = o.parent;
570		}
571		return false;
572	};
573
574	/**
575	 * @method toString
576	 * @return {String} a string representation of the instance.
577	 **/
578	p.toString = function() {
579		return &quot;[EventDispatcher]&quot;;
580	};
581
582
583// private methods:
584	/**
585	 * @method _dispatchEvent
586	 * @param {Object | Event} eventObj
587	 * @param {Object} eventPhase
588	 * @protected
589	 **/
590	p._dispatchEvent = function(eventObj, eventPhase) {
591		var l, arr, listeners = (eventPhase &lt;= 2) ? this._captureListeners : this._listeners;
592		if (eventObj &amp;&amp; listeners &amp;&amp; (arr = listeners[eventObj.type]) &amp;&amp; (l=arr.length)) {
593			try { eventObj.currentTarget = this; } catch (e) {}
594			try { eventObj.eventPhase = eventPhase|0; } catch (e) {}
595			eventObj.removed = false;
596			
597			arr = arr.slice(); // to avoid issues with items being removed or added during the dispatch
598			for (var i=0; i&lt;l &amp;&amp; !eventObj.immediatePropagationStopped; i++) {
599				var o = arr[i];
600				if (o.handleEvent) { o.handleEvent(eventObj); }
601				else { o(eventObj); }
602				if (eventObj.removed) {
603					this.off(eventObj.type, o, eventPhase==1);
604					eventObj.removed = false;
605				}
606			}
607		}
608		if (eventPhase === 2) { this._dispatchEvent(eventObj, 2.1); }
609	};
610
611
612	createjs.EventDispatcher = EventDispatcher;
613}());
614
615    </pre>
616</div>
617
618                    </div>
619                </div>
620            </div>
621        </div>
622    </div>
623</div>
624<script src="../assets/vendor/prettify/prettify-min.js"></script>
625<script>prettyPrint();</script>
626<script src="../assets/js/yui-prettify.js"></script>
627<script src="../assets/../api.js"></script>
628<script src="../assets/js/api-filter.js"></script>
629<script src="../assets/js/api-list.js"></script>
630<script src="../assets/js/api-search.js"></script>
631<script src="../assets/js/apidocs.js"></script>
632</body>
633</html>