libraries/EaselJS_docs/files/easeljs_display_MovieClip.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 : easeljs/display/MovieClip.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 = easeljs/display/MovieClip.js
200</script>
201<h1 class="file-heading">File:MovieClip.js</h1>
202
203<div class="file">
204 <pre class="code prettyprint linenums">
205/*
206* MovieClip
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 "Software"), 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 "AS IS", 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 EaselJS
235 */
236
237// namespace:
238this.createjs = this.createjs||{};
239
240(function() {
241 "use strict";
242
243
244// constructor:
245 /**
246 * The MovieClip class associates a TweenJS Timeline with an EaselJS {{#crossLink "Container"}}{{/crossLink}}. It allows
247 * you to create objects which encapsulate timeline animations, state changes, and synched actions. The MovieClip
248 * class has been included in the EaselJS minified file since 0.7.0.
249 *
250 * Currently MovieClip only works properly if it is tick based (as opposed to time based) though some concessions have
251 * been made to support time-based timelines in the future.
252 *
253 * <h4>Example</h4>
254 * This example animates two shapes back and forth. The grey shape starts on the left, but we jump to a mid-point in
255 * the animation using {{#crossLink "MovieClip/gotoAndPlay"}}{{/crossLink}}.
256 *
257 * var stage = new createjs.Stage("canvas");
258 * createjs.Ticker.addEventListener("tick", stage);
259 *
260 * var mc = new createjs.MovieClip({loop:-1, labels:{myLabel:20}});
261 * stage.addChild(mc);
262 *
263 * var child1 = new createjs.Shape(
264 * new createjs.Graphics().beginFill("#999999")
265 * .drawCircle(30,30,30));
266 * var child2 = new createjs.Shape(
267 * new createjs.Graphics().beginFill("#5a9cfb")
268 * .drawCircle(30,30,30));
269 *
270 * mc.timeline.addTween(
271 * createjs.Tween.get(child1)
272 * .to({x:0}).to({x:60}, 50).to({x:0}, 50));
273 * mc.timeline.addTween(
274 * createjs.Tween.get(child2)
275 * .to({x:60}).to({x:0}, 50).to({x:60}, 50));
276 *
277 * mc.gotoAndPlay("start");
278 *
279 * It is recommended to use <code>tween.to()</code> to animate and set properties (use no duration to have it set
280 * immediately), and the <code>tween.wait()</code> method to create delays between animations. Note that using the
281 * <code>tween.set()</code> method to affect properties will likely not provide the desired result.
282 *
283 * @class MovieClip
284 * @main MovieClip
285 * @param {Object} [props] The configuration properties to apply to this instance (ex. `{mode:MovieClip.SYNCHED}`).
286 * Supported props for the MovieClip are listed below. These props are set on the corresponding instance properties except where
287 * specified.<UL>
288 * <LI> `mode`</LI>
289 * <LI> `startPosition`</LI>
290 * <LI> `frameBounds`</LI>
291 * </UL>
292 *
293 * This object will also be passed into the Timeline instance associated with this MovieClip. See the documentation
294 * for Timeline for a list of supported props (ex. `paused`, `labels`, `loop`, `reversed`, etc.)
295 * @extends Container
296 * @constructor
297 **/
298 function MovieClip(props) {
299 this.Container_constructor();
300 !MovieClip.inited&&MovieClip.init(); // static init
301
302 var mode, startPosition, loop, labels;
303
304 // handle old params (mode, startPosition, loop, labels):
305 // TODO: deprecated param handling:
306 if (props instanceof String || arguments.length > 1) {
307 mode = props;
308 startPosition = arguments[1];
309 loop = arguments[2];
310 labels = arguments[3];
311 if (loop == null) { loop = -1; }
312 props = null;
313 } else if (props) {
314 mode = props.mode;
315 startPosition = props.startPosition;
316 loop = props.loop;
317 labels = props.labels;
318 }
319 if (!props) { props = {labels:labels}; }
320
321
322 // public properties:
323 /**
324 * Controls how this MovieClip advances its time. Must be one of 0 (INDEPENDENT), 1 (SINGLE_FRAME), or 2 (SYNCHED).
325 * See each constant for a description of the behaviour.
326 * @property mode
327 * @type String
328 * @default null
329 **/
330 this.mode = mode||MovieClip.INDEPENDENT;
331
332 /**
333 * Specifies what the first frame to play in this movieclip, or the only frame to display if mode is SINGLE_FRAME.
334 * @property startPosition
335 * @type Number
336 * @default 0
337 */
338 this.startPosition = startPosition||0;
339
340 /**
341 * Specifies how many times this MovieClip should loop. A value of -1 indicates it should loop indefinitely. A value of
342 * 1 would cause it to loop once (ie. play a total of twice).
343 * @property loop
344 * @type Number
345 * @default -1
346 */
347 this.loop = loop === true ? -1 : (loop || 0);
348
349 /**
350 * The current frame of the movieclip.
351 * @property currentFrame
352 * @type Number
353 * @default 0
354 * @readonly
355 */
356 this.currentFrame = 0;
357
358 /**
359 * If true, the MovieClip's position will not advance when ticked.
360 * @property paused
361 * @type Boolean
362 * @default false
363 */
364 this.paused = props.paused||false;
365
366 /**
367 * If true, actions in this MovieClip's tweens will be run when the playhead advances.
368 * @property actionsEnabled
369 * @type Boolean
370 * @default true
371 */
372 this.actionsEnabled = true;
373
374 /**
375 * If true, the MovieClip will automatically be reset to its first frame whenever the timeline adds
376 * it back onto the display list. This only applies to MovieClip instances with mode=INDEPENDENT.
377 * <br><br>
378 * For example, if you had a character animation with a "body" child MovieClip instance
379 * with different costumes on each frame, you could set body.autoReset = false, so that
380 * you can manually change the frame it is on, without worrying that it will be reset
381 * automatically.
382 * @property autoReset
383 * @type Boolean
384 * @default true
385 */
386 this.autoReset = true;
387
388 /**
389 * An array of bounds for each frame in the MovieClip. This is mainly intended for tool output.
390 * @property frameBounds
391 * @type Array
392 * @default null
393 */
394 this.frameBounds = this.frameBounds||props.frameBounds; // frameBounds are set on the prototype in Animate.
395
396 /**
397 * By default MovieClip instances advance one frame per tick. Specifying a framerate for the MovieClip
398 * will cause it to advance based on elapsed time between ticks as appropriate to maintain the target
399 * framerate.
400 *
401 * For example, if a MovieClip with a framerate of 10 is placed on a Stage being updated at 40fps, then the MovieClip will
402 * advance roughly one frame every 4 ticks. This will not be exact, because the time between each tick will
403 * vary slightly between frames.
404 *
405 * This feature is dependent on the tick event object (or an object with an appropriate "delta" property) being
406 * passed into {{#crossLink "Stage/update"}}{{/crossLink}}.
407 * @property framerate
408 * @type {Number}
409 * @default null
410 **/
411 this.framerate = null;
412
413 // set up the needed props for Timeline:
414 props.useTicks = props.paused = true;
415
416 /**
417 * The TweenJS Timeline that is associated with this MovieClip. This is created automatically when the MovieClip
418 * instance is initialized. Animations are created by adding <a href="http://tweenjs.com">TweenJS</a> Tween
419 * instances to the timeline.
420 *
421 * <h4>Example</h4>
422 *
423 * var tween = createjs.Tween.get(target).to({x:0}).to({x:100}, 30);
424 * var mc = new createjs.MovieClip();
425 * mc.timeline.addTween(tween);
426 *
427 * Elements can be added and removed from the timeline by toggling an "_off" property
428 * using the <code>tweenInstance.to()</code> method. Note that using <code>Tween.set</code> is not recommended to
429 * create MovieClip animations. The following example will toggle the target off on frame 0, and then back on for
430 * frame 1. You can use the "visible" property to achieve the same effect.
431 *
432 * var tween = createjs.Tween.get(target).to({_off:false})
433 * .wait(1).to({_off:true})
434 * .wait(1).to({_off:false});
435 *
436 * @property timeline
437 * @type Timeline
438 * @default null
439 */
440 this.timeline = new createjs.Timeline(props);
441
442
443 // private properties:
444 /**
445 * @property _synchOffset
446 * @type Number
447 * @default 0
448 * @private
449 */
450 this._synchOffset = 0;
451
452 /**
453 * @property _rawPosition
454 * @type Number
455 * @default -1
456 * @private
457 */
458 this._rawPosition = -1; // TODO: evaluate using a ._reset Boolean prop instead of -1.
459
460 /**
461 * @property _bound_resolveState
462 * @type Function
463 * @private
464 */
465 this._bound_resolveState = this._resolveState.bind(this);
466
467
468 /**
469 * The time remaining from the previous tick, only applicable when .framerate is set.
470 * @property _t
471 * @type Number
472 * @private
473 */
474 this._t = 0;
475
476 /**
477 * List of display objects that are actively being managed by the MovieClip.
478 * @property _managed
479 * @type Object
480 * @private
481 */
482 this._managed = {};
483 }
484 var p = createjs.extend(MovieClip, createjs.Container);
485
486
487// constants:
488 /**
489 * The MovieClip will advance independently of its parent, even if its parent is paused.
490 * This is the default mode.
491 * @property INDEPENDENT
492 * @static
493 * @type String
494 * @default "independent"
495 * @readonly
496 **/
497 MovieClip.INDEPENDENT = "independent";
498
499 /**
500 * The MovieClip will only display a single frame (as determined by the startPosition property).
501 * @property SINGLE_FRAME
502 * @static
503 * @type String
504 * @default "single"
505 * @readonly
506 **/
507 MovieClip.SINGLE_FRAME = "single";
508
509 /**
510 * The MovieClip will be advanced only when its parent advances and will be synched to the position of
511 * the parent MovieClip.
512 * @property SYNCHED
513 * @static
514 * @type String
515 * @default "synched"
516 * @readonly
517 **/
518 MovieClip.SYNCHED = "synched";
519
520
521// static properties:
522 MovieClip.inited = false;
523
524
525// static methods:
526 MovieClip.init = function() {
527 if (MovieClip.inited) { return; }
528 // plugins introduce some overhead to Tween, so we only install this if an MC is instantiated.
529 MovieClipPlugin.install();
530 MovieClip.inited = true;
531 };
532
533
534// getter / setters:
535 /**
536 * Use the {{#crossLink "MovieClip/labels:property"}}{{/crossLink}} property instead.
537 * @method _getLabels
538 * @protected
539 * @return {Array}
540 **/
541 p._getLabels = function() {
542 return this.timeline.getLabels();
543 };
544 // MovieClip.getLabels is @deprecated. Remove for 1.1+
545 p.getLabels = createjs.deprecate(p._getLabels, "MovieClip.getLabels");
546
547 /**
548 * Use the {{#crossLink "MovieClip/currentLabel:property"}}{{/crossLink}} property instead.
549 * @method _getCurrentLabel
550 * @protected
551 * @return {String}
552 **/
553 p._getCurrentLabel = function() {
554 return this.timeline.currentLabel;
555 };
556 // MovieClip.getCurrentLabel is @deprecated. Remove for 1.1+
557 p.getCurrentLabel = createjs.deprecate(p._getCurrentLabel, "MovieClip.getCurrentLabel");
558
559 /**
560 * Use the {{#crossLink "MovieClip/duration:property"}}{{/crossLink}} property instead.
561 * @method _getDuration
562 * @protected
563 * @return {Number}
564 **/
565 p._getDuration = function() {
566 return this.timeline.duration;
567 };
568 // MovieClip.getDuration is @deprecated. Remove for 1.1+
569 p.getDuration = createjs.deprecate(p._getDuration, "MovieClip.getDuration");
570
571 /**
572 * Returns an array of objects with label and position (aka frame) properties, sorted by position.
573 * @property labels
574 * @type {Array}
575 * @readonly
576 **/
577
578 /**
579 * Returns the name of the label on or immediately before the current frame.
580 * @property currentLabel
581 * @type {String}
582 * @readonly
583 **/
584
585 /**
586 * Returns the duration of this MovieClip in seconds or ticks.
587 * @property totalFrames
588 * @type {Number}
589 * @readonly
590 **/
591
592 /**
593 * Returns the duration of this MovieClip in seconds or ticks.
594 * @property duration
595 * @type {Number}
596 * @readonly
597 **/
598 try {
599 Object.defineProperties(p, {
600 labels: { get: p._getLabels },
601 currentLabel: { get: p._getCurrentLabel },
602 totalFrames: { get: p._getDuration },
603 duration: { get: p._getDuration }
604 // TODO: can we just proxy .currentFrame to tl.position as well? Ditto for .loop (or just remove entirely).
605 });
606 } catch (e) {}
607
608
609// public methods:
610 /**
611 * Constructor alias for backwards compatibility. This method will be removed in future versions.
612 * Subclasses should be updated to use {{#crossLink "Utility Methods/extends"}}{{/crossLink}}.
613 * @method initialize
614 * @deprecated in favour of `createjs.promote()`
615 **/
616 p.initialize = MovieClip; // TODO: Deprecated. This is for backwards support of Adobe Flash/Animate
617
618 /**
619 * Returns true or false indicating whether the display object would be visible if drawn to a canvas.
620 * This does not account for whether it would be visible within the boundaries of the stage.
621 * NOTE: This method is mainly for internal use, though it may be useful for advanced uses.
622 * @method isVisible
623 * @return {Boolean} Boolean indicating whether the display object would be visible if drawn to a canvas
624 **/
625 p.isVisible = function() {
626 // children are placed in draw, so we can't determine if we have content.
627 return !!(this.visible && this.alpha > 0 && this.scaleX != 0 && this.scaleY != 0);
628 };
629
630 /**
631 * Draws the display object into the specified context ignoring its visible, alpha, shadow, and transform.
632 * Returns true if the draw was handled (useful for overriding functionality).
633 * NOTE: This method is mainly for internal use, though it may be useful for advanced uses.
634 * @method draw
635 * @param {CanvasRenderingContext2D} ctx The canvas 2D context object to draw into.
636 * @param {Boolean} ignoreCache Indicates whether the draw operation should ignore any current cache.
637 * For example, used for drawing the cache (to prevent it from simply drawing an existing cache back
638 * into itself).
639 **/
640 p.draw = function(ctx, ignoreCache) {
641 // draw to cache first:
642 if (this.DisplayObject_draw(ctx, ignoreCache)) { return true; }
643 this._updateState();
644 this.Container_draw(ctx, ignoreCache);
645 return true;
646 };
647
648 /**
649 * Sets paused to false.
650 * @method play
651 **/
652 p.play = function() {
653 this.paused = false;
654 };
655
656 /**
657 * Sets paused to true.
658 * @method stop
659 **/
660 p.stop = function() {
661 this.paused = true;
662 };
663
664 /**
665 * Advances this movie clip to the specified position or label and sets paused to false.
666 * @method gotoAndPlay
667 * @param {String|Number} positionOrLabel The animation name or frame number to go to.
668 **/
669 p.gotoAndPlay = function(positionOrLabel) {
670 this.paused = false;
671 this._goto(positionOrLabel);
672 };
673
674 /**
675 * Advances this movie clip to the specified position or label and sets paused to true.
676 * @method gotoAndStop
677 * @param {String|Number} positionOrLabel The animation or frame name to go to.
678 **/
679 p.gotoAndStop = function(positionOrLabel) {
680 this.paused = true;
681 this._goto(positionOrLabel);
682 };
683
684 /**
685 * Advances the playhead. This occurs automatically each tick by default.
686 * @param [time] {Number} The amount of time in ms to advance by. Only applicable if framerate is set.
687 * @method advance
688 */
689 p.advance = function(time) {
690 var independent = MovieClip.INDEPENDENT;
691 if (this.mode !== independent) { return; } // update happens in draw for synched clips
692
693 // if this MC doesn't have a framerate, hunt ancestors for one:
694 var o=this, fps = o.framerate;
695 while ((o = o.parent) && fps === null) { if (o.mode === independent) { fps = o._framerate; } }
696 this._framerate = fps;
697
698 if (this.paused) { return; }
699
700 // calculate how many frames to advance:
701 var t = (fps !== null && fps !== -1 && time !== null) ? time/(1000/fps) + this._t : 1;
702 var frames = t|0;
703 this._t = t-frames; // leftover time, save to add to next advance.
704
705 while (frames--) { this._updateTimeline(this._rawPosition+1, false); }
706 };
707
708 /**
709 * MovieClip instances cannot be cloned.
710 * @method clone
711 **/
712 p.clone = function() {
713 // TODO: add support for this? Need to clone the Timeline & retarget tweens - pretty complex.
714 throw("MovieClip cannot be cloned.");
715 };
716
717 /**
718 * Returns a string representation of this object.
719 * @method toString
720 * @return {String} a string representation of the instance.
721 **/
722 p.toString = function() {
723 return "[MovieClip (name="+ this.name +")]";
724 };
725
726
727// private methods:
728 /**
729 * Docced in superclass.
730 **/
731 p._updateState = function() {
732 if (this._rawPosition === -1 || this.mode !== MovieClip.INDEPENDENT) { this._updateTimeline(-1); }
733 };
734
735 /**
736 * @method _tick
737 * @param {Object} evtObj An event object that will be dispatched to all tick listeners. This object is reused between dispatchers to reduce construction & GC costs.
738 * function.
739 * @protected
740 **/
741 p._tick = function(evtObj) {
742 this.advance(evtObj&&evtObj.delta);
743 this.Container__tick(evtObj);
744 };
745
746 /**
747 * @method _goto
748 * @param {String|Number} positionOrLabel The animation name or frame number to go to.
749 * @protected
750 **/
751 p._goto = function(positionOrLabel) {
752 var pos = this.timeline.resolve(positionOrLabel);
753 if (pos == null) { return; }
754 this._t = 0;
755 this._updateTimeline(pos, true);
756 };
757
758 /**
759 * @method _reset
760 * @private
761 **/
762 p._reset = function() {
763 this._rawPosition = -1;
764 this._t = this.currentFrame = 0;
765 this.paused = false;
766 };
767
768 /**
769 * @method _updateTimeline
770 * @param {Boolean} jump Indicates whether this update is due to jumping (via gotoAndXX) to a new position.
771 * @protected
772 **/
773 p._updateTimeline = function(rawPosition, jump) {
774 var synced = this.mode !== MovieClip.INDEPENDENT, tl = this.timeline;
775 if (synced) { rawPosition = this.startPosition + (this.mode===MovieClip.SINGLE_FRAME?0:this._synchOffset); }
776 if (rawPosition < 0) { rawPosition = 0; }
777 if (this._rawPosition === rawPosition && !synced) { return; }
778 this._rawPosition = rawPosition;
779
780 // update timeline position, ignoring actions if this is a graphic.
781 tl.loop = this.loop; // TODO: should we maintain this on MovieClip, or just have it on timeline?
782 tl.setPosition(rawPosition, synced || !this.actionsEnabled, jump, this._bound_resolveState);
783 };
784
785 /**
786 * Renders position 0 without running actions or updating _rawPosition.
787 * Primarily used by Animate CC to build out the first frame in the constructor of MC symbols.
788 * NOTE: not tested when run after the MC advances past the first frame.
789 * @method _renderFirstFrame
790 * @protected
791 **/
792 p._renderFirstFrame = function() {
793 var tl = this.timeline, pos = tl.rawPosition;
794 tl.setPosition(0, true, true, this._bound_resolveState);
795 tl.rawPosition = pos;
796 };
797
798 /**
799 * Runs via a callback after timeline property updates and before actions.
800 * @method _resolveState
801 * @protected
802 **/
803 p._resolveState = function() {
804 var tl = this.timeline;
805 this.currentFrame = tl.position;
806
807 for (var n in this._managed) { this._managed[n] = 1; }
808
809 var tweens = tl.tweens;
810 for (var i=0, l=tweens.length; i<l; i++) {
811 var tween = tweens[i], target = tween.target;
812 if (target === this || tween.passive) { continue; } // TODO: this assumes the actions tween from Animate has `this` as the target. There's likely a better approach.
813 var offset = tween._stepPosition;
814
815 if (target instanceof createjs.DisplayObject) {
816 // motion tween.
817 this._addManagedChild(target, offset);
818 } else {
819 // state tween.
820 this._setState(target.state, offset);
821 }
822 }
823
824 var kids = this.children;
825 for (i=kids.length-1; i>=0; i--) {
826 var id = kids[i].id;
827 if (this._managed[id] === 1) {
828 this.removeChildAt(i);
829 delete(this._managed[id]);
830 }
831 }
832 };
833
834 /**
835 * @method _setState
836 * @param {Array} state
837 * @param {Number} offset
838 * @protected
839 **/
840 p._setState = function(state, offset) {
841 if (!state) { return; }
842 for (var i=state.length-1;i>=0;i--) {
843 var o = state[i];
844 var target = o.t;
845 var props = o.p;
846 for (var n in props) { target[n] = props[n]; }
847 this._addManagedChild(target, offset);
848 }
849 };
850
851 /**
852 * Adds a child to the timeline, and sets it up as a managed child.
853 * @method _addManagedChild
854 * @param {MovieClip} child The child MovieClip to manage
855 * @param {Number} offset
856 * @private
857 **/
858 p._addManagedChild = function(child, offset) {
859 if (child._off) { return; }
860 this.addChildAt(child,0);
861
862 if (child instanceof MovieClip) {
863 child._synchOffset = offset;
864 // TODO: this does not precisely match Adobe Flash/Animate, which loses track of the clip if it is renamed or removed from the timeline, which causes it to reset.
865 // TODO: should also reset when MovieClip loops, though that will be a bit tricky to detect.
866 if (child.mode === MovieClip.INDEPENDENT && child.autoReset && (!this._managed[child.id])) { child._reset(); }
867 }
868 this._managed[child.id] = 2;
869 };
870
871 /**
872 * @method _getBounds
873 * @param {Matrix2D} matrix
874 * @param {Boolean} ignoreTransform
875 * @return {Rectangle}
876 * @protected
877 **/
878 p._getBounds = function(matrix, ignoreTransform) {
879 var bounds = this.DisplayObject_getBounds();
880 if (!bounds) {
881 if (this.frameBounds) { bounds = this._rectangle.copy(this.frameBounds[this.currentFrame]); }
882 }
883 if (bounds) { return this._transformBounds(bounds, matrix, ignoreTransform); }
884 return this.Container__getBounds(matrix, ignoreTransform);
885 };
886
887
888 createjs.MovieClip = createjs.promote(MovieClip, "Container");
889
890
891
892// MovieClipPlugin for TweenJS:
893 /**
894 * This plugin works with <a href="http://tweenjs.com" target="_blank">TweenJS</a> to prevent the startPosition
895 * property from tweening.
896 * @private
897 * @class MovieClipPlugin
898 * @constructor
899 **/
900 function MovieClipPlugin() {
901 throw("MovieClipPlugin cannot be instantiated.")
902 }
903
904 /**
905 * @property priority
906 * @type {Number}
907 * @static
908 * @readonly
909 **/
910 MovieClipPlugin.priority = 100; // very high priority, should run first
911
912 /**
913 * @property ID
914 * @type {String}
915 * @static
916 * @readonly
917 **/
918 MovieClipPlugin.ID = "MovieClip";
919
920 /**
921 * @method install
922 * @static
923 **/
924 MovieClipPlugin.install = function() {
925 createjs.Tween._installPlugin(MovieClipPlugin);
926 };
927
928 /**
929 * @method init
930 * @param {Tween} tween
931 * @param {String} prop
932 * @param {*} value
933 * @static
934 **/
935 MovieClipPlugin.init = function(tween, prop, value) {
936 if (prop === "startPosition" && tween.target instanceof MovieClip) { tween._addPlugin(MovieClipPlugin); }
937 };
938
939 /**
940 * @method step
941 * @param {Tween} tween
942 * @param {TweenStep} step
943 * @param {Object} props
944 * @static
945 **/
946 MovieClipPlugin.step = function(tween, step, props) {};
947
948 /**
949 * @method change
950 * @param {Tween} tween
951 * @param {TweenStep} step
952 * @param {*} value
953 * @param {Number} ratio
954 * @param {Object} end
955 * @return {*}
956 * @static
957 */
958 MovieClipPlugin.change = function(tween, step, prop, value, ratio, end) {
959 if (prop === "startPosition") { return (ratio === 1 ? step.props[prop] : step.prev.props[prop]); }
960 };
961
962}());
963
964 </pre>
965</div>
966
967 </div>
968 </div>
969 </div>
970 </div>
971 </div>
972</div>
973<script src="../assets/vendor/prettify/prettify-min.js"></script>
974<script>prettyPrint();</script>
975<script src="../assets/js/yui-prettify.js"></script>
976<script src="../assets/../api.js"></script>
977<script src="../assets/js/api-filter.js"></script>
978<script src="../assets/js/api-list.js"></script>
979<script src="../assets/js/api-search.js"></script>
980<script src="../assets/js/apidocs.js"></script>
981</body>
982</html>