mobile-graphic-easel-src-easeljs-display-MovieClip.js / js
The MovieClip class associates a TweenJS Timeline with an EaselJS {{#crossLink "Container"}}{{/crossLink}}. It allows you to create objects which encapsulate timeline animations, state changes, and synched actions. Due to the complexities inherent in correctly setting up a MovieClip, it is largely intended for tool output and is not included in the main EaselJS library. Currently MovieClip only works properly if it is tick based (as opposed to time based) though some concessions have been made to support time-based timelines in the future. <h4>Example</h4> This example animates two shapes back and forth. The grey shape starts on the left, but we jump to a mid-point in the animation using {{#crossLink "MovieClip/gotoAndPlay"}}{{/crossLink}}. var stage = new createjs.Stage("canvas"); createjs.Ticker.addEventListener("tick", stage); var mc = new createjs.MovieClip(null, 0, true, {start:20}); stage.addChild(mc); var child1 = new createjs.Shape( new createjs.Graphics().beginFill("#999999") .drawCircle(30,30,30)); var child2 = new createjs.Shape( new createjs.Graphics().beginFill("#5a9cfb") .drawCircle(30,30,30)); mc.timeline.addTween( createjs.Tween.get(child1) .to({x:0}).to({x:60}, 50).to({x:0}, 50)); mc.timeline.addTween( createjs.Tween.get(child2) .to({x:60}).to({x:0}, 50).to({x:60}, 50)); mc.gotoAndPlay("start"); It is recommended to use <code>tween.to()</code> to animate and set properties (use no duration to have it set immediately), and the <code>tween.wait()</code> method to create delays between animations. Note that using the <code>tween.set()</code> method to affect properties will likely not provide the desired result. @class MovieClip @main MovieClip @extends Container @constructor
parameter: {String} [mode=independent] Initial value for the mode property. One of MovieClip.INDEPENDENT, MovieClip.SINGLE_FRAME, or MovieClip.SYNCHED. The default is MovieClip.INDEPENDENT.
parameter: {Number} [startPosition=0] Initial value for the startPosition property.
parameter: {Boolean} [loop=true] Initial value for the loop property. The default is true.
parameter: {Object} [labels=null] A hash of labels to pass to the timeline instance associated with this MovieClip. Labels only need to be passed if they need to be used.
Read-only. The MovieClip will advance independently of its parent, even if its parent is paused. This is the default mode. @property INDEPENDENT @static @type String @default "independent"
Read-only. The MovieClip will only display a single frame (as determined by the startPosition property). @property SINGLE_FRAME @static @type String @default "single"
Read-only. The MovieClip will be advanced only when it's parent advances and will be synched to the position of the parent MovieClip. @property SYNCHED @static @type String @default "synched"
Controls how this MovieClip advances its time. Must be one of 0 (INDEPENDENT), 1 (SINGLE_FRAME), or 2 (SYNCHED). See each constant for a description of the behaviour. @property mode @type String @default null
Specifies what the first frame to play in this movieclip, or the only frame to display if mode is SINGLE_FRAME. @property startPosition @type Number @default 0
Indicates whether this MovieClip should loop when it reaches the end of its timeline. @property loop @type Boolean @default true
Read-Only. The current frame of the movieclip. @property currentFrame @type Number
The TweenJS Timeline that is associated with this MovieClip. This is created automatically when the MovieClip instance is initialized. Animations are created by adding <a href="http://tweenjs.com">TweenJS</a> Tween instances to the timeline. <h4>Example</h4> var tween = createjs.Tween.get(target).to({x:0}).to({x:100}, 30); var mc = new createjs.MovieClip(); mc.timeline.addTween(tween); Elements can be added and removed from the timeline by toggling an "_off" property using the <code>tweenInstance.to()</code> method. Note that using <code>Tween.set</code> is not recommended to create MovieClip animations. The following example will toggle the target off on frame 0, and then back on for frame 1. You can use the "visible" property to achieve the same effect. var tween = createjs.Tween.get(target).to({_off:false}) .wait(1).to({_off:true}) .wait(1).to({_off:false}); @property timeline @type Timeline @default null
If true, the MovieClip's position will not advance when ticked. @property paused @type Boolean @default false
If true, actions in this MovieClip's tweens will be run when the playhead advances. @property actionsEnabled @type Boolean @default true
If true, the MovieClip will automatically be reset to its first frame whenever the timeline adds it back onto the display list. This only applies to MovieClip instances with mode=INDEPENDENT. <br><br> For example, if you had a character animation with a "body" child MovieClip instance with different costumes on each frame, you could set body.autoReset = false, so that you can manually change the frame it is on, without worrying that it will be reset automatically. @property autoReset @type Boolean @default true
@property _synchOffset @type Number @default 0 @private
@property _prevPos @type Number @default -1 @private
@property _prevPosition @type Number @default 0 @private
List of display objects that are actively being managed by the MovieClip. @property _managed @type Object @private
@property DisplayObject_initialize @type Function @private
Initialization method called by the constructor. @method initialize @protected
Returns true or false indicating whether the display object would be visible if drawn to a canvas. This does not account for whether it would be visible within the boundaries of the stage. NOTE: This method is mainly for internal use, though it may be useful for advanced uses. @method isVisible
returns: {Boolean} Boolean indicating whether the display object would be visible if drawn to a canvas
@property Container_draw @type Function @private
Draws the display object into the specified context ignoring it's visible, alpha, shadow, and transform. Returns true if the draw was handled (useful for overriding functionality). NOTE: This method is mainly for internal use, though it may be useful for advanced uses. @method draw
parameter: {CanvasRenderingContext2D} ctx The canvas 2D context object to draw into.
parameter: {Boolean} ignoreCache Indicates whether the draw operation should ignore any current cache. For example, used for drawing the cache (to prevent it from simply drawing an existing cache back into itself).
Sets paused to false. @method play
Sets paused to true. @method stop
Advances this movie clip to the specified position or label and sets paused to false. @method gotoAndPlay
parameter: {String|Number} positionOrLabel
Advances this movie clip to the specified position or label and sets paused to true. @method gotoAndStop
parameter: {String|Number} positionOrLabel
MovieClip instances cannot be cloned. @method clone
Returns a string representation of this object. @method toString
returns: {String} a string representation of the instance.
@property Container__tick @type Function @private
@method _tick @private
@method _goto @private
@method _reset @private
@method _updateTimeline @private
@method _setState @private
Adds a child to the timeline, and sets it up as a managed child. @method _addManagedChild @private
This plugin works with <a href="http://tweenjs.com" target="_blank">TweenJS</a> to prevent the startPosition property from tweening. @private @class MovieClipPlugin @constructor
@method priority @private
@method install @private
@method init @private
@method step @private
@method tween @private
(C) Æliens 04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.