libraries/EaselJS_docs/classes/EventDispatcher.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 : EventDispatcher</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">
198 <h1>EventDispatcher Class</h1>
199<div class="box meta">
200
201
202
203
204
205 <div class="foundat">
206 Defined in: <a href="../files/createjs_events_EventDispatcher.js.html#l41"><code>EventDispatcher:41</code></a>
207 </div>
208
209
210
211
212 Module: <a href="../modules/CreateJS.html">CreateJS</a>
213
214
215
216
217</div>
218
219
220
221<div class="box intro">
222 <p>EventDispatcher provides methods for managing queues of event listeners and dispatching events.</p>
223<p>You can either extend EventDispatcher or mix its methods into an existing prototype or instance by using the
224EventDispatcher <a href="../classes/EventDispatcher.html#method_initialize" class="crosslink">initialize</a> method.</p>
225<p>Together with the CreateJS Event class, EventDispatcher provides an extended event model that is based on the
226DOM Level 2 event model, including addEventListener, removeEventListener, and dispatchEvent. It supports
227bubbling / capture, preventDefault, stopPropagation, stopImmediatePropagation, and handleEvent.</p>
228<p>EventDispatcher also exposes a <a href="../classes/EventDispatcher.html#method_on" class="crosslink">on</a> method, which makes it easier
229to create scoped listeners, listeners that only run once, and listeners with associated arbitrary data. The
230<a href="../classes/EventDispatcher.html#method_off" class="crosslink">off</a> method is merely an alias to
231<a href="../classes/EventDispatcher.html#method_removeEventListener" class="crosslink">removeEventListener</a>.</p>
232<p>Another addition to the DOM Level 2 model is the <a href="../classes/EventDispatcher.html#method_removeAllEventListeners" class="crosslink">removeAllEventListeners</a>
233method, which can be used to listeners for all events, or listeners for a specific event. The Event object also
234includes a <a href="../classes/Event.html#method_remove" class="crosslink">remove</a> method which removes the active listener.</p>
235<p><h4>Example</h4>
236Add EventDispatcher capabilities to the "MyClass" class.</p>
237<pre class="code prettyprint"><code> EventDispatcher.initialize(MyClass.prototype);</code></pre>
238<p>Add an event (see <a href="../classes/EventDispatcher.html#method_addEventListener" class="crosslink">addEventListener</a>).</p>
239<pre class="code prettyprint"><code> instance.addEventListener("eventName", handlerMethod);
240 function handlerMethod(event) {
241 console.log(event.target + " Was Clicked");
242 }</code></pre>
243<p><b>Maintaining proper scope</b><br />
244Scope (ie. "this") can be be a challenge with events. Using the <a href="../classes/EventDispatcher.html#method_on" class="crosslink">on</a>
245method to subscribe to events simplifies this.</p>
246<pre class="code prettyprint"><code> instance.addEventListener("click", function(event) {
247 console.log(instance == this); // false, scope is ambiguous.
248 });
249
250 instance.on("click", function(event) {
251 console.log(instance == this); // true, "on" uses dispatcher scope by default.
252 });</code></pre>
253<p>If you want to use addEventListener instead, you may want to use function.bind() or a similar proxy to manage
254scope.</p>
255<p><b>Browser support</b>
256The event model in CreateJS can be used separately from the suite in any project, however the inheritance model
257requires modern browsers (IE9+).</p>
258
259</div>
260
261
262 <div class="constructor">
263 <h2>Constructor</h2>
264 <div id="method_EventDispatcher" class="method item">
265 <h3 class="name"><code>EventDispatcher</code></h3>
266
267
268 <span class="paren">()</span>
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285 <div class="meta">
286
287
288
289 <p>
290
291 Defined in
292
293
294
295
296 <a href="../files/createjs_events_EventDispatcher.js.html#l41"><code>EventDispatcher:41</code></a>
297
298 </p>
299
300
301
302
303
304 </div>
305
306 <div class="description">
307
308 </div>
309
310
311
312
313
314
315</div>
316
317 </div>
318
319
320<div id="classdocs" class="tabview">
321 <ul class="api-class-tabs">
322 <li class="api-class-tab index"><a href="#index">Index</a></li>
323
324
325 <li class="api-class-tab methods"><a href="#methods">Methods</a></li>
326
327
328 <li class="api-class-tab properties"><a href="#properties">Properties</a></li>
329
330
331
332 </ul>
333
334 <div>
335 <div id="index" class="api-class-tabpanel index">
336 <h2 class="off-left">Item Index</h2>
337
338
339 <div class="index-section methods">
340 <h3>Methods</h3>
341
342 <ul class="index-list methods">
343
344 <li class="index-item method protected">
345 <a href="#method__dispatchEvent">_dispatchEvent</a>
346
347
348
349 </li>
350
351 <li class="index-item method">
352 <a href="#method_addEventListener">addEventListener</a>
353
354
355
356 </li>
357
358 <li class="index-item method">
359 <a href="#method_dispatchEvent">dispatchEvent</a>
360
361
362
363 </li>
364
365 <li class="index-item method">
366 <a href="#method_hasEventListener">hasEventListener</a>
367
368
369
370 </li>
371
372 <li class="index-item method">
373 <a href="#method_initialize">initialize</a>
374
375
376 <span class="flag static">static</span>
377
378
379 </li>
380
381 <li class="index-item method">
382 <a href="#method_off">off</a>
383
384
385
386 </li>
387
388 <li class="index-item method">
389 <a href="#method_on">on</a>
390
391
392
393 </li>
394
395 <li class="index-item method">
396 <a href="#method_removeAllEventListeners">removeAllEventListeners</a>
397
398
399
400 </li>
401
402 <li class="index-item method">
403 <a href="#method_removeEventListener">removeEventListener</a>
404
405
406
407 </li>
408
409 <li class="index-item method">
410 <a href="#method_toString">toString</a>
411
412
413
414 </li>
415
416 <li class="index-item method">
417 <a href="#method_willTrigger">willTrigger</a>
418
419
420
421 </li>
422
423 </ul>
424 </div>
425
426
427
428 <div class="index-section properties">
429 <h3>Properties</h3>
430
431 <ul class="index-list properties">
432
433 <li class="index-item property protected">
434 <a href="#property__captureListeners">_captureListeners</a>
435
436
437
438 </li>
439
440 <li class="index-item property protected">
441 <a href="#property__listeners">_listeners</a>
442
443
444
445 </li>
446
447 </ul>
448 </div>
449
450
451
452
453
454 </div>
455
456
457 <div id="methods" class="api-class-tabpanel">
458 <h2 class="off-left">Methods</h2>
459
460
461 <div id="method__dispatchEvent" class="method item protected">
462 <h3 class="name"><code>_dispatchEvent</code></h3>
463
464
465 <div class="args">
466 <span class="paren">(</span><ul class="args-list inline commas">
467
468 <li class="arg">
469
470 <code>eventObj</code>
471
472 </li>
473
474 <li class="arg">
475
476 <code>eventPhase</code>
477
478 </li>
479
480 </ul><span class="paren">)</span>
481 </div>
482
483
484
485
486
487
488
489 <span class="flag protected">protected</span>
490
491
492
493
494
495
496
497
498
499
500 <div class="meta">
501
502
503
504 <p>
505
506 Defined in
507
508
509
510
511 <a href="../files/createjs_events_EventDispatcher.js.html#l380"><code>_dispatchEvent:380</code></a>
512
513 </p>
514
515
516
517
518
519 </div>
520
521 <div class="description">
522
523 </div>
524
525
526 <div class="params">
527 <h4>Parameters:</h4>
528
529 <ul class="params-list">
530
531 <li class="param">
532
533 <code class="param-name">eventObj</code>
534 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object" class="crosslink external" target="_blank">Object</a> | <a href="../classes/Event.html" class="crosslink">Event</a></span>
535
536
537
538
539 <div class="param-description">
540
541 </div>
542
543
544 </li>
545
546 <li class="param">
547
548 <code class="param-name">eventPhase</code>
549 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object" class="crosslink external" target="_blank">Object</a></span>
550
551
552
553
554 <div class="param-description">
555
556 </div>
557
558
559 </li>
560
561 </ul>
562 </div>
563
564
565
566
567
568</div>
569
570
571 <div id="method_addEventListener" class="method item">
572 <h3 class="name"><code>addEventListener</code></h3>
573
574
575 <div class="args">
576 <span class="paren">(</span><ul class="args-list inline commas">
577
578 <li class="arg">
579
580 <code>type</code>
581
582 </li>
583
584 <li class="arg">
585
586 <code>listener</code>
587
588 </li>
589
590 <li class="arg">
591
592 <code class="optional">[useCapture]</code>
593
594 </li>
595
596 </ul><span class="paren">)</span>
597 </div>
598
599
600
601 <span class="returns-inline">
602 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function" class="crosslink external" target="_blank">Function</a> | <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object" class="crosslink external" target="_blank">Object</a></span>
603 </span>
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618 <div class="meta">
619
620
621
622 <p>
623
624 Defined in
625
626
627
628
629 <a href="../files/createjs_events_EventDispatcher.js.html#l140"><code>addEventListener:140</code></a>
630
631 </p>
632
633
634
635
636
637 </div>
638
639 <div class="description">
640 <p>Adds the specified event listener. Note that adding multiple listeners to the same function will result in
641multiple callbacks getting fired.</p>
642<h4>Example</h4>
643
644<pre class="code prettyprint"><code> displayObject.addEventListener("click", handleClick);
645 function handleClick(event) {
646 // Click happened.
647 }</code></pre>
648
649 </div>
650
651
652 <div class="params">
653 <h4>Parameters:</h4>
654
655 <ul class="params-list">
656
657 <li class="param">
658
659 <code class="param-name">type</code>
660 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String" class="crosslink external" target="_blank">String</a></span>
661
662
663
664
665 <div class="param-description">
666 <p>The string type of the event.</p>
667
668 </div>
669
670
671 </li>
672
673 <li class="param">
674
675 <code class="param-name">listener</code>
676 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function" class="crosslink external" target="_blank">Function</a> | <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object" class="crosslink external" target="_blank">Object</a></span>
677
678
679
680
681 <div class="param-description">
682 <p>An object with a handleEvent method, or a function that will be called when
683the event is dispatched.</p>
684
685 </div>
686
687
688 </li>
689
690 <li class="param">
691
692 <code class="param-name optional">[useCapture]</code>
693 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Boolean" class="crosslink external" target="_blank">Boolean</a></span>
694 <span class="flag optional" title="This parameter is optional.">optional</span>
695
696
697
698
699 <div class="param-description">
700 <p>For events that bubble, indicates whether to listen for the event in the capture or bubbling/target phase.</p>
701
702 </div>
703
704
705 </li>
706
707 </ul>
708 </div>
709
710
711
712 <div class="returns">
713 <h4>Returns:</h4>
714
715 <div class="returns-description">
716
717
718 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function" class="crosslink external" target="_blank">Function</a> | <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object" class="crosslink external" target="_blank">Object</a></span>:
719
720 <p>Returns the listener for chaining or assignment.</p>
721
722
723 </div>
724 </div>
725
726
727
728</div>
729
730
731 <div id="method_dispatchEvent" class="method item">
732 <h3 class="name"><code>dispatchEvent</code></h3>
733
734
735 <div class="args">
736 <span class="paren">(</span><ul class="args-list inline commas">
737
738 <li class="arg">
739
740 <code>eventObj</code>
741
742 </li>
743
744 <li class="arg">
745
746 <code class="optional">[bubbles]</code>
747
748 </li>
749
750 <li class="arg">
751
752 <code class="optional">[cancelable]</code>
753
754 </li>
755
756 </ul><span class="paren">)</span>
757 </div>
758
759
760
761 <span class="returns-inline">
762 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Boolean" class="crosslink external" target="_blank">Boolean</a></span>
763 </span>
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778 <div class="meta">
779
780
781
782 <p>
783
784 Defined in
785
786
787
788
789 <a href="../files/createjs_events_EventDispatcher.js.html#l285"><code>dispatchEvent:285</code></a>
790
791 </p>
792
793
794
795
796
797 </div>
798
799 <div class="description">
800 <p>Dispatches the specified event to all listeners.</p>
801<h4>Example</h4>
802
803<pre class="code prettyprint"><code> // Use a string event
804 this.dispatchEvent("complete");
805
806 // Use an Event instance
807 var event = new createjs.Event("progress");
808 this.dispatchEvent(event);</code></pre>
809
810 </div>
811
812
813 <div class="params">
814 <h4>Parameters:</h4>
815
816 <ul class="params-list">
817
818 <li class="param">
819
820 <code class="param-name">eventObj</code>
821 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object" class="crosslink external" target="_blank">Object</a> | <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String" class="crosslink external" target="_blank">String</a> | <a href="../classes/Event.html" class="crosslink">Event</a></span>
822
823
824
825
826 <div class="param-description">
827 <p>An object with a "type" property, or a string type.
828While a generic object will work, it is recommended to use a CreateJS Event instance. If a string is used,
829dispatchEvent will construct an Event instance if necessary with the specified type. This latter approach can
830be used to avoid event object instantiation for non-bubbling events that may not have any listeners.</p>
831
832 </div>
833
834
835 </li>
836
837 <li class="param">
838
839 <code class="param-name optional">[bubbles]</code>
840 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Boolean" class="crosslink external" target="_blank">Boolean</a></span>
841 <span class="flag optional" title="This parameter is optional.">optional</span>
842
843
844
845
846 <div class="param-description">
847 <p>Specifies the <code>bubbles</code> value when a string was passed to eventObj.</p>
848
849 </div>
850
851
852 </li>
853
854 <li class="param">
855
856 <code class="param-name optional">[cancelable]</code>
857 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Boolean" class="crosslink external" target="_blank">Boolean</a></span>
858 <span class="flag optional" title="This parameter is optional.">optional</span>
859
860
861
862
863 <div class="param-description">
864 <p>Specifies the <code>cancelable</code> value when a string was passed to eventObj.</p>
865
866 </div>
867
868
869 </li>
870
871 </ul>
872 </div>
873
874
875
876 <div class="returns">
877 <h4>Returns:</h4>
878
879 <div class="returns-description">
880
881
882 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Boolean" class="crosslink external" target="_blank">Boolean</a></span>:
883
884 <p>Returns false if <code>preventDefault()</code> was called on a cancelable event, true otherwise.</p>
885
886
887 </div>
888 </div>
889
890
891
892</div>
893
894
895 <div id="method_hasEventListener" class="method item">
896 <h3 class="name"><code>hasEventListener</code></h3>
897
898
899 <div class="args">
900 <span class="paren">(</span><ul class="args-list inline commas">
901
902 <li class="arg">
903
904 <code>type</code>
905
906 </li>
907
908 </ul><span class="paren">)</span>
909 </div>
910
911
912
913 <span class="returns-inline">
914 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Boolean" class="crosslink external" target="_blank">Boolean</a></span>
915 </span>
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930 <div class="meta">
931
932
933
934 <p>
935
936 Defined in
937
938
939
940
941 <a href="../files/createjs_events_EventDispatcher.js.html#l339"><code>hasEventListener:339</code></a>
942
943 </p>
944
945
946
947
948
949 </div>
950
951 <div class="description">
952 <p>Indicates whether there is at least one listener for the specified event type.</p>
953
954 </div>
955
956
957 <div class="params">
958 <h4>Parameters:</h4>
959
960 <ul class="params-list">
961
962 <li class="param">
963
964 <code class="param-name">type</code>
965 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String" class="crosslink external" target="_blank">String</a></span>
966
967
968
969
970 <div class="param-description">
971 <p>The string type of the event.</p>
972
973 </div>
974
975
976 </li>
977
978 </ul>
979 </div>
980
981
982
983 <div class="returns">
984 <h4>Returns:</h4>
985
986 <div class="returns-description">
987
988
989 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Boolean" class="crosslink external" target="_blank">Boolean</a></span>:
990
991 <p>Returns true if there is at least one listener for the specified event.</p>
992
993
994 </div>
995 </div>
996
997
998
999</div>
1000
1001
1002 <div id="method_initialize" class="method item">
1003 <h3 class="name"><code>initialize</code></h3>
1004
1005
1006 <div class="args">
1007 <span class="paren">(</span><ul class="args-list inline commas">
1008
1009 <li class="arg">
1010
1011 <code>target</code>
1012
1013 </li>
1014
1015 </ul><span class="paren">)</span>
1016 </div>
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028 <span class="flag static">static</span>
1029
1030
1031
1032
1033
1034
1035 <div class="meta">
1036
1037
1038
1039 <p>
1040
1041 Defined in
1042
1043
1044
1045
1046 <a href="../files/createjs_events_EventDispatcher.js.html#l116"><code>initialize:116</code></a>
1047
1048 </p>
1049
1050
1051
1052
1053
1054 </div>
1055
1056 <div class="description">
1057 <p>Static initializer to mix EventDispatcher methods into a target object or prototype.</p>
1058<pre class="code prettyprint"><code> EventDispatcher.initialize(MyClass.prototype); // add to the prototype of the class
1059 EventDispatcher.initialize(myObject); // add to a specific instance</code></pre>
1060
1061 </div>
1062
1063
1064 <div class="params">
1065 <h4>Parameters:</h4>
1066
1067 <ul class="params-list">
1068
1069 <li class="param">
1070
1071 <code class="param-name">target</code>
1072 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object" class="crosslink external" target="_blank">Object</a></span>
1073
1074
1075
1076
1077 <div class="param-description">
1078 <p>The target object to inject EventDispatcher methods into. This can be an instance or a
1079prototype.</p>
1080
1081 </div>
1082
1083
1084 </li>
1085
1086 </ul>
1087 </div>
1088
1089
1090
1091
1092
1093</div>
1094
1095
1096 <div id="method_off" class="method item">
1097 <h3 class="name"><code>off</code></h3>
1098
1099
1100 <div class="args">
1101 <span class="paren">(</span><ul class="args-list inline commas">
1102
1103 <li class="arg">
1104
1105 <code>type</code>
1106
1107 </li>
1108
1109 <li class="arg">
1110
1111 <code>listener</code>
1112
1113 </li>
1114
1115 <li class="arg">
1116
1117 <code class="optional">[useCapture]</code>
1118
1119 </li>
1120
1121 </ul><span class="paren">)</span>
1122 </div>
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139 <div class="meta">
1140
1141
1142
1143 <p>
1144
1145 Defined in
1146
1147
1148
1149
1150 <a href="../files/createjs_events_EventDispatcher.js.html#l249"><code>off:249</code></a>
1151
1152 </p>
1153
1154
1155
1156
1157
1158 </div>
1159
1160 <div class="description">
1161 <p>A shortcut to the removeEventListener method, with the same parameters and return value. This is a companion to the
1162.on method.</p>
1163<p><b>IMPORTANT:</b> To remove a listener added with <code>on</code>, you must pass in the returned wrapper function as the listener. See
1164<a href="../classes/EventDispatcher.html#method_on" class="crosslink">on</a> for an example.</p>
1165
1166 </div>
1167
1168
1169 <div class="params">
1170 <h4>Parameters:</h4>
1171
1172 <ul class="params-list">
1173
1174 <li class="param">
1175
1176 <code class="param-name">type</code>
1177 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String" class="crosslink external" target="_blank">String</a></span>
1178
1179
1180
1181
1182 <div class="param-description">
1183 <p>The string type of the event.</p>
1184
1185 </div>
1186
1187
1188 </li>
1189
1190 <li class="param">
1191
1192 <code class="param-name">listener</code>
1193 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function" class="crosslink external" target="_blank">Function</a> | <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object" class="crosslink external" target="_blank">Object</a></span>
1194
1195
1196
1197
1198 <div class="param-description">
1199 <p>The listener function or object.</p>
1200
1201 </div>
1202
1203
1204 </li>
1205
1206 <li class="param">
1207
1208 <code class="param-name optional">[useCapture]</code>
1209 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Boolean" class="crosslink external" target="_blank">Boolean</a></span>
1210 <span class="flag optional" title="This parameter is optional.">optional</span>
1211
1212
1213
1214
1215 <div class="param-description">
1216 <p>For events that bubble, indicates whether to listen for the event in the capture or bubbling/target phase.</p>
1217
1218 </div>
1219
1220
1221 </li>
1222
1223 </ul>
1224 </div>
1225
1226
1227
1228
1229
1230</div>
1231
1232
1233 <div id="method_on" class="method item">
1234 <h3 class="name"><code>on</code></h3>
1235
1236
1237 <div class="args">
1238 <span class="paren">(</span><ul class="args-list inline commas">
1239
1240 <li class="arg">
1241
1242 <code>type</code>
1243
1244 </li>
1245
1246 <li class="arg">
1247
1248 <code>listener</code>
1249
1250 </li>
1251
1252 <li class="arg">
1253
1254 <code class="optional">[scope]</code>
1255
1256 </li>
1257
1258 <li class="arg">
1259
1260 <code class="optional">[once=false]</code>
1261
1262 </li>
1263
1264 <li class="arg">
1265
1266 <code class="optional">[data]</code>
1267
1268 </li>
1269
1270 <li class="arg">
1271
1272 <code class="optional">[useCapture=false]</code>
1273
1274 </li>
1275
1276 </ul><span class="paren">)</span>
1277 </div>
1278
1279
1280
1281 <span class="returns-inline">
1282 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function" class="crosslink external" target="_blank">Function</a></span>
1283 </span>
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298 <div class="meta">
1299
1300
1301
1302 <p>
1303
1304 Defined in
1305
1306
1307
1308
1309 <a href="../files/createjs_events_EventDispatcher.js.html#l173"><code>on:173</code></a>
1310
1311 </p>
1312
1313
1314
1315
1316
1317 </div>
1318
1319 <div class="description">
1320 <p>A shortcut method for using addEventListener that makes it easier to specify an execution scope, have a listener
1321only run once, associate arbitrary data with the listener, and remove the listener.</p>
1322<p>This method works by creating an anonymous wrapper function and subscribing it with addEventListener.
1323The wrapper function is returned for use with <code>removeEventListener</code> (or <code>off</code>).</p>
1324<p><b>IMPORTANT:</b> To remove a listener added with <code>on</code>, you must pass in the returned wrapper function as the listener, or use
1325<a href="../classes/Event.html#method_remove" class="crosslink">remove</a>. Likewise, each time you call <code>on</code> a NEW wrapper function is subscribed, so multiple calls
1326to <code>on</code> with the same params will create multiple listeners.</p>
1327<h4>Example</h4>
1328
1329<pre class="code prettyprint"><code> var listener = myBtn.on("click", handleClick, null, false, {count:3});
1330 function handleClick(evt, data) {
1331 data.count -= 1;
1332 console.log(this == myBtn); // true - scope defaults to the dispatcher
1333 if (data.count == 0) {
1334 alert("clicked 3 times!");
1335 myBtn.off("click", listener);
1336 // alternately: evt.remove();
1337 }
1338 }</code></pre>
1339
1340 </div>
1341
1342
1343 <div class="params">
1344 <h4>Parameters:</h4>
1345
1346 <ul class="params-list">
1347
1348 <li class="param">
1349
1350 <code class="param-name">type</code>
1351 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String" class="crosslink external" target="_blank">String</a></span>
1352
1353
1354
1355
1356 <div class="param-description">
1357 <p>The string type of the event.</p>
1358
1359 </div>
1360
1361
1362 </li>
1363
1364 <li class="param">
1365
1366 <code class="param-name">listener</code>
1367 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function" class="crosslink external" target="_blank">Function</a> | <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object" class="crosslink external" target="_blank">Object</a></span>
1368
1369
1370
1371
1372 <div class="param-description">
1373 <p>An object with a handleEvent method, or a function that will be called when
1374the event is dispatched.</p>
1375
1376 </div>
1377
1378
1379 </li>
1380
1381 <li class="param">
1382
1383 <code class="param-name optional">[scope]</code>
1384 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object" class="crosslink external" target="_blank">Object</a></span>
1385 <span class="flag optional" title="This parameter is optional.">optional</span>
1386
1387
1388
1389
1390 <div class="param-description">
1391 <p>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).</p>
1392
1393 </div>
1394
1395
1396 </li>
1397
1398 <li class="param">
1399
1400 <code class="param-name optional">[once=false]</code>
1401 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Boolean" class="crosslink external" target="_blank">Boolean</a></span>
1402 <span class="flag optional" title="This parameter is optional.">optional</span>
1403
1404
1405
1406
1407 <div class="param-description">
1408 <p>If true, the listener will remove itself after the first time it is triggered.</p>
1409
1410 </div>
1411
1412
1413 </li>
1414
1415 <li class="param">
1416
1417 <code class="param-name optional">[data]</code>
1418 <span class="type"></span>
1419 <span class="flag optional" title="This parameter is optional.">optional</span>
1420
1421
1422
1423
1424 <div class="param-description">
1425 <p>Arbitrary data that will be included as the second parameter when the listener is called.</p>
1426
1427 </div>
1428
1429
1430 </li>
1431
1432 <li class="param">
1433
1434 <code class="param-name optional">[useCapture=false]</code>
1435 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Boolean" class="crosslink external" target="_blank">Boolean</a></span>
1436 <span class="flag optional" title="This parameter is optional.">optional</span>
1437
1438
1439
1440
1441 <div class="param-description">
1442 <p>For events that bubble, indicates whether to listen for the event in the capture or bubbling/target phase.</p>
1443
1444 </div>
1445
1446
1447 </li>
1448
1449 </ul>
1450 </div>
1451
1452
1453
1454 <div class="returns">
1455 <h4>Returns:</h4>
1456
1457 <div class="returns-description">
1458
1459
1460 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function" class="crosslink external" target="_blank">Function</a></span>:
1461
1462 <p>Returns the anonymous function that was created and assigned as the listener. This is needed to remove the listener later using .removeEventListener.</p>
1463
1464
1465 </div>
1466 </div>
1467
1468
1469
1470</div>
1471
1472
1473 <div id="method_removeAllEventListeners" class="method item">
1474 <h3 class="name"><code>removeAllEventListeners</code></h3>
1475
1476
1477 <div class="args">
1478 <span class="paren">(</span><ul class="args-list inline commas">
1479
1480 <li class="arg">
1481
1482 <code class="optional">[type]</code>
1483
1484 </li>
1485
1486 </ul><span class="paren">)</span>
1487 </div>
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504 <div class="meta">
1505
1506
1507
1508 <p>
1509
1510 Defined in
1511
1512
1513
1514
1515 <a href="../files/createjs_events_EventDispatcher.js.html#l263"><code>removeAllEventListeners:263</code></a>
1516
1517 </p>
1518
1519
1520
1521
1522
1523 </div>
1524
1525 <div class="description">
1526 <p>Removes all listeners for the specified type, or all listeners of all types.</p>
1527<h4>Example</h4>
1528
1529<pre class="code prettyprint"><code> // Remove all listeners
1530 displayObject.removeAllEventListeners();
1531
1532 // Remove all click listeners
1533 displayObject.removeAllEventListeners("click");</code></pre>
1534
1535 </div>
1536
1537
1538 <div class="params">
1539 <h4>Parameters:</h4>
1540
1541 <ul class="params-list">
1542
1543 <li class="param">
1544
1545 <code class="param-name optional">[type]</code>
1546 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String" class="crosslink external" target="_blank">String</a></span>
1547 <span class="flag optional" title="This parameter is optional.">optional</span>
1548
1549
1550
1551
1552 <div class="param-description">
1553 <p>The string type of the event. If omitted, all listeners for all types will be removed.</p>
1554
1555 </div>
1556
1557
1558 </li>
1559
1560 </ul>
1561 </div>
1562
1563
1564
1565
1566
1567</div>
1568
1569
1570 <div id="method_removeEventListener" class="method item">
1571 <h3 class="name"><code>removeEventListener</code></h3>
1572
1573
1574 <div class="args">
1575 <span class="paren">(</span><ul class="args-list inline commas">
1576
1577 <li class="arg">
1578
1579 <code>type</code>
1580
1581 </li>
1582
1583 <li class="arg">
1584
1585 <code>listener</code>
1586
1587 </li>
1588
1589 <li class="arg">
1590
1591 <code class="optional">[useCapture]</code>
1592
1593 </li>
1594
1595 </ul><span class="paren">)</span>
1596 </div>
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613 <div class="meta">
1614
1615
1616
1617 <p>
1618
1619 Defined in
1620
1621
1622
1623
1624 <a href="../files/createjs_events_EventDispatcher.js.html#l219"><code>removeEventListener:219</code></a>
1625
1626 </p>
1627
1628
1629
1630
1631
1632 </div>
1633
1634 <div class="description">
1635 <p>Removes the specified event listener.</p>
1636<p><b>Important Note:</b> that you must pass the exact function reference used when the event was added. If a proxy
1637function, or function closure is used as the callback, the proxy/closure reference must be used - a new proxy or
1638closure will not work.</p>
1639<h4>Example</h4>
1640
1641<pre class="code prettyprint"><code> displayObject.removeEventListener("click", handleClick);</code></pre>
1642
1643 </div>
1644
1645
1646 <div class="params">
1647 <h4>Parameters:</h4>
1648
1649 <ul class="params-list">
1650
1651 <li class="param">
1652
1653 <code class="param-name">type</code>
1654 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String" class="crosslink external" target="_blank">String</a></span>
1655
1656
1657
1658
1659 <div class="param-description">
1660 <p>The string type of the event.</p>
1661
1662 </div>
1663
1664
1665 </li>
1666
1667 <li class="param">
1668
1669 <code class="param-name">listener</code>
1670 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function" class="crosslink external" target="_blank">Function</a> | <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object" class="crosslink external" target="_blank">Object</a></span>
1671
1672
1673
1674
1675 <div class="param-description">
1676 <p>The listener function or object.</p>
1677
1678 </div>
1679
1680
1681 </li>
1682
1683 <li class="param">
1684
1685 <code class="param-name optional">[useCapture]</code>
1686 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Boolean" class="crosslink external" target="_blank">Boolean</a></span>
1687 <span class="flag optional" title="This parameter is optional.">optional</span>
1688
1689
1690
1691
1692 <div class="param-description">
1693 <p>For events that bubble, indicates whether to listen for the event in the capture or bubbling/target phase.</p>
1694
1695 </div>
1696
1697
1698 </li>
1699
1700 </ul>
1701 </div>
1702
1703
1704
1705
1706
1707</div>
1708
1709
1710 <div id="method_toString" class="method item">
1711 <h3 class="name"><code>toString</code></h3>
1712
1713
1714 <span class="paren">()</span>
1715
1716
1717
1718 <span class="returns-inline">
1719 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String" class="crosslink external" target="_blank">String</a></span>
1720 </span>
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735 <div class="meta">
1736
1737
1738
1739 <p>
1740
1741 Defined in
1742
1743
1744
1745
1746 <a href="../files/createjs_events_EventDispatcher.js.html#l370"><code>toString:370</code></a>
1747
1748 </p>
1749
1750
1751
1752
1753
1754 </div>
1755
1756 <div class="description">
1757
1758 </div>
1759
1760
1761
1762
1763 <div class="returns">
1764 <h4>Returns:</h4>
1765
1766 <div class="returns-description">
1767
1768
1769 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String" class="crosslink external" target="_blank">String</a></span>:
1770
1771 <p>a string representation of the instance.</p>
1772
1773
1774 </div>
1775 </div>
1776
1777
1778
1779</div>
1780
1781
1782 <div id="method_willTrigger" class="method item">
1783 <h3 class="name"><code>willTrigger</code></h3>
1784
1785
1786 <div class="args">
1787 <span class="paren">(</span><ul class="args-list inline commas">
1788
1789 <li class="arg">
1790
1791 <code>type</code>
1792
1793 </li>
1794
1795 </ul><span class="paren">)</span>
1796 </div>
1797
1798
1799
1800 <span class="returns-inline">
1801 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Boolean" class="crosslink external" target="_blank">Boolean</a></span>
1802 </span>
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817 <div class="meta">
1818
1819
1820
1821 <p>
1822
1823 Defined in
1824
1825
1826
1827
1828 <a href="../files/createjs_events_EventDispatcher.js.html#l350"><code>willTrigger:350</code></a>
1829
1830 </p>
1831
1832
1833
1834
1835
1836 </div>
1837
1838 <div class="description">
1839 <p>Indicates whether there is at least one listener for the specified event type on this object or any of its
1840ancestors (parent, parent's parent, etc). A return value of true indicates that if a bubbling event of the
1841specified type is dispatched from this object, it will trigger at least one listener.</p>
1842<p>This is similar to <a href="../classes/EventDispatcher.html#method_hasEventListener" class="crosslink">hasEventListener</a>, but it searches the entire
1843event flow for a listener, not just this object.</p>
1844
1845 </div>
1846
1847
1848 <div class="params">
1849 <h4>Parameters:</h4>
1850
1851 <ul class="params-list">
1852
1853 <li class="param">
1854
1855 <code class="param-name">type</code>
1856 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String" class="crosslink external" target="_blank">String</a></span>
1857
1858
1859
1860
1861 <div class="param-description">
1862 <p>The string type of the event.</p>
1863
1864 </div>
1865
1866
1867 </li>
1868
1869 </ul>
1870 </div>
1871
1872
1873
1874 <div class="returns">
1875 <h4>Returns:</h4>
1876
1877 <div class="returns-description">
1878
1879
1880 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Boolean" class="crosslink external" target="_blank">Boolean</a></span>:
1881
1882 <p>Returns <code>true</code> if there is at least one listener for the specified event.</p>
1883
1884
1885 </div>
1886 </div>
1887
1888
1889
1890</div>
1891
1892
1893 </div>
1894
1895
1896
1897 <div id="properties" class="api-class-tabpanel">
1898 <h2 class="off-left">Properties</h2>
1899
1900
1901 <div id="property__captureListeners" class="property item protected">
1902 <h3 class="name"><code>_captureListeners</code></h3>
1903 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object" class="crosslink external" target="_blank">Object</a></span>
1904
1905
1906
1907
1908 <span class="flag protected">protected</span>
1909
1910
1911
1912
1913
1914
1915
1916
1917 <div class="meta">
1918
1919
1920
1921 <p>
1922
1923 Defined in
1924
1925
1926
1927
1928 <a href="../files/createjs_events_EventDispatcher.js.html#l106"><code>_captureListeners:106</code></a>
1929
1930 </p>
1931
1932
1933
1934
1935 </div>
1936
1937 <div class="description">
1938
1939 </div>
1940
1941
1942
1943
1944
1945
1946</div>
1947
1948
1949 <div id="property__listeners" class="property item protected">
1950 <h3 class="name"><code>_listeners</code></h3>
1951 <span class="type"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object" class="crosslink external" target="_blank">Object</a></span>
1952
1953
1954
1955
1956 <span class="flag protected">protected</span>
1957
1958
1959
1960
1961
1962
1963
1964
1965 <div class="meta">
1966
1967
1968
1969 <p>
1970
1971 Defined in
1972
1973
1974
1975
1976 <a href="../files/createjs_events_EventDispatcher.js.html#l99"><code>_listeners:99</code></a>
1977
1978 </p>
1979
1980
1981
1982
1983 </div>
1984
1985 <div class="description">
1986
1987 </div>
1988
1989
1990
1991
1992
1993
1994</div>
1995
1996
1997 </div>
1998
1999
2000
2001
2002
2003 </div>
2004</div>
2005
2006 </div>
2007 </div>
2008 </div>
2009 </div>
2010 </div>
2011</div>
2012<script src="../assets/vendor/prettify/prettify-min.js"></script>
2013<script>prettyPrint();</script>
2014<script src="../assets/js/yui-prettify.js"></script>
2015<script src="../assets/../api.js"></script>
2016<script src="../assets/js/api-filter.js"></script>
2017<script src="../assets/js/api-list.js"></script>
2018<script src="../assets/js/api-search.js"></script>
2019<script src="../assets/js/apidocs.js"></script>
2020</body>
2021</html>