all repos — simplyrpg @ 05a250383b5037effb602fc3ca4d2bb1cdf4da90

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

libraries/EaselJS_docs/files/easeljs_display_Sprite.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/Sprite.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/Sprite.js      
200</script>
201<h1 class="file-heading">File:Sprite.js</h1>
202
203<div class="file">
204    <pre class="code prettyprint linenums">
205/*
206* Sprite
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 EaselJS
235 */
236
237// namespace:
238this.createjs = this.createjs||{};
239
240(function() {
241	&quot;use strict&quot;;
242
243
244// constructor:
245	/**
246	 * Displays a frame or sequence of frames (ie. an animation) from a SpriteSheet instance. A sprite sheet is a series of
247	 * images (usually animation frames) combined into a single image. For example, an animation consisting of 8 100x100
248	 * images could be combined into a 400x200 sprite sheet (4 frames across by 2 high). You can display individual frames,
249	 * play frames as an animation, and even sequence animations together.
250	 *
251	 * See the {{#crossLink &quot;SpriteSheet&quot;}}{{/crossLink}} class for more information on setting up frames and animations.
252	 *
253	 * &lt;h4&gt;Example&lt;/h4&gt;
254	 *
255	 *      var instance = new createjs.Sprite(spriteSheet);
256	 *      instance.gotoAndStop(&quot;frameName&quot;);
257	 *
258	 * Until {{#crossLink &quot;Sprite/gotoAndStop&quot;}}{{/crossLink}} or {{#crossLink &quot;Sprite/gotoAndPlay&quot;}}{{/crossLink}} is called,
259	 * only the first defined frame defined in the sprite sheet will be displayed.
260	 *
261	 * @class Sprite
262	 * @extends DisplayObject
263	 * @constructor
264	 * @param {SpriteSheet} spriteSheet The SpriteSheet instance to play back. This includes the source image(s), frame
265	 * dimensions, and frame data. See {{#crossLink &quot;SpriteSheet&quot;}}{{/crossLink}} for more information.
266	 * @param {String|Number} [frameOrAnimation] The frame number or animation to play initially.
267	 **/
268	function Sprite(spriteSheet, frameOrAnimation) {
269		this.DisplayObject_constructor();
270		
271		
272	// public properties:
273		/**
274		 * The frame index that will be drawn when draw is called. Note that with some {{#crossLink &quot;SpriteSheet&quot;}}{{/crossLink}}
275		 * definitions, this will advance non-sequentially. This will always be an integer value.
276		 * @property currentFrame
277		 * @type {Number}
278		 * @default 0
279		 * @readonly
280		 **/
281		this.currentFrame = 0;
282	
283		/**
284		 * Returns the name of the currently playing animation.
285		 * @property currentAnimation
286		 * @type {String}
287		 * @final
288		 * @readonly
289		 **/
290		this.currentAnimation = null;
291	
292		/**
293		 * Prevents the animation from advancing each tick automatically. For example, you could create a sprite
294		 * sheet of icons, set paused to true, and display the appropriate icon by setting &lt;code&gt;currentFrame&lt;/code&gt;.
295		 * @property paused
296		 * @type {Boolean}
297		 * @default false
298		 **/
299		this.paused = true;
300	
301		/**
302		 * The SpriteSheet instance to play back. This includes the source image, frame dimensions, and frame
303		 * data. See {{#crossLink &quot;SpriteSheet&quot;}}{{/crossLink}} for more information.
304		 * @property spriteSheet
305		 * @type {SpriteSheet}
306		 * @readonly
307		 **/
308		this.spriteSheet = spriteSheet;
309	
310		/**
311		 * Specifies the current frame index within the currently playing animation. When playing normally, this will increase
312		 * from 0 to n-1, where n is the number of frames in the current animation.
313		 *
314		 * This could be a non-integer value if
315		 * using time-based playback (see {{#crossLink &quot;Sprite/framerate&quot;}}{{/crossLink}}, or if the animation&#x27;s speed is
316		 * not an integer.
317		 * @property currentAnimationFrame
318		 * @type {Number}
319		 * @default 0
320		 **/
321		this.currentAnimationFrame = 0;
322	
323		/**
324		 * By default Sprite instances advance one frame per tick. Specifying a framerate for the Sprite (or its related
325		 * SpriteSheet) will cause it to advance based on elapsed time between ticks as appropriate to maintain the target
326		 * framerate.
327		 *
328		 * For example, if a Sprite with a framerate of 10 is placed on a Stage being updated at 40fps, then the Sprite will
329		 * advance roughly one frame every 4 ticks. This will not be exact, because the time between each tick will
330		 * vary slightly between frames.
331		 *
332		 * This feature is dependent on the tick event object (or an object with an appropriate &quot;delta&quot; property) being
333		 * passed into {{#crossLink &quot;Stage/update&quot;}}{{/crossLink}}.
334		 * @property framerate
335		 * @type {Number}
336		 * @default 0
337		 **/
338		this.framerate = 0;
339	
340	
341	// private properties:
342		/**
343		 * Current animation object.
344		 * @property _animation
345		 * @protected
346		 * @type {Object}
347		 * @default null
348		 **/
349		this._animation = null;
350	
351		/**
352		 * Current frame index.
353		 * @property _currentFrame
354		 * @protected
355		 * @type {Number}
356		 * @default null
357		 **/
358		this._currentFrame = null;
359		
360		/**
361		 * Skips the next auto advance. Used by gotoAndPlay to avoid immediately jumping to the next frame
362		 * @property _skipAdvance
363		 * @protected
364		 * @type {Boolean}
365		 * @default false
366		 **/
367		this._skipAdvance = false;
368
369		/**
370		 * Docced in superclass.
371		 */
372		this._webGLRenderStyle = createjs.DisplayObject._StageGL_SPRITE;
373
374		if (frameOrAnimation != null) { this.gotoAndPlay(frameOrAnimation); }
375	}
376	var p = createjs.extend(Sprite, createjs.DisplayObject);
377
378	/**
379	 * Constructor alias for backwards compatibility. This method will be removed in future versions.
380	 * Subclasses should be updated to use {{#crossLink &quot;Utility Methods/extends&quot;}}{{/crossLink}}.
381	 * @method initialize
382	 * @deprecated in favour of &#x60;createjs.promote()&#x60;
383	 **/
384	p.initialize = Sprite; // TODO: Deprecated. This is for backwards support of Flash/Animate spritesheet export.
385
386
387// events:
388	/**
389	 * Dispatched when an animation reaches its ends.
390	 * @event animationend
391	 * @param {Object} target The object that dispatched the event.
392	 * @param {String} type The event type.
393	 * @param {String} name The name of the animation that just ended.
394	 * @param {String} next The name of the next animation that will be played, or null. This will be the same as name if the animation is looping.
395	 * @since 0.6.0
396	 */
397	 
398	/**
399	 * Dispatched any time the current frame changes. For example, this could be due to automatic advancement on a tick,
400	 * or calling gotoAndPlay() or gotoAndStop().
401	 * @event change
402	 * @param {Object} target The object that dispatched the event.
403	 * @param {String} type The event type.
404	 */
405
406
407// public methods:
408	/**
409	 * Returns true or false indicating whether the display object would be visible if drawn to a canvas.
410	 * This does not account for whether it would be visible within the boundaries of the stage.
411	 * NOTE: This method is mainly for internal use, though it may be useful for advanced uses.
412	 * @method isVisible
413	 * @return {Boolean} Boolean indicating whether the display object would be visible if drawn to a canvas
414	 **/
415	p.isVisible = function() {
416		var hasContent = this.cacheCanvas || this.spriteSheet.complete;
417		return !!(this.visible &amp;&amp; this.alpha &gt; 0 &amp;&amp; this.scaleX != 0 &amp;&amp; this.scaleY != 0 &amp;&amp; hasContent);
418	};
419
420	/**
421	 * Draws the display object into the specified context ignoring its visible, alpha, shadow, and transform.
422	 * Returns true if the draw was handled (useful for overriding functionality).
423	 * NOTE: This method is mainly for internal use, though it may be useful for advanced uses.
424	 * @method draw
425	 * @param {CanvasRenderingContext2D} ctx The canvas 2D context object to draw into.
426	 * @param {Boolean} ignoreCache Indicates whether the draw operation should ignore any current cache.
427	 * For example, used for drawing the cache (to prevent it from simply drawing an existing cache back
428	 * into itself).
429	 **/
430	p.draw = function(ctx, ignoreCache) {
431		if (this.DisplayObject_draw(ctx, ignoreCache)) { return true; }
432		this._normalizeFrame();
433		var o = this.spriteSheet.getFrame(this._currentFrame|0);
434		if (!o) { return false; }
435		var rect = o.rect;
436		if (rect.width &amp;&amp; rect.height) { ctx.drawImage(o.image, rect.x, rect.y, rect.width, rect.height, -o.regX, -o.regY, rect.width, rect.height); }
437		return true;
438	};
439
440	//Note, the doc sections below document using the specified APIs (from DisplayObject)  from
441	//Bitmap. This is why they have no method implementations.
442
443	/**
444	 * Because the content of a Sprite is already in a raster format, cache is unnecessary for Sprite instances.
445	 * You should not cache Sprite instances as it can degrade performance.
446	 * @method cache
447	 **/
448
449	/**
450	 * Because the content of a Sprite is already in a raster format, cache is unnecessary for Sprite instances.
451	 * You should not cache Sprite instances as it can degrade performance.
452	 * @method updateCache
453	 **/
454
455	/**
456	 * Because the content of a Sprite is already in a raster format, cache is unnecessary for Sprite instances.
457	 * You should not cache Sprite instances as it can degrade performance.
458	 * @method uncache
459	 **/
460
461	/**
462	 * Play (unpause) the current animation. The Sprite will be paused if either {{#crossLink &quot;Sprite/stop&quot;}}{{/crossLink}}
463	 * or {{#crossLink &quot;Sprite/gotoAndStop&quot;}}{{/crossLink}} is called. Single frame animations will remain
464	 * unchanged.
465	 * @method play
466	 **/
467	p.play = function() {
468		this.paused = false;
469	};
470
471	/**
472	 * Stop playing a running animation. The Sprite will be playing if {{#crossLink &quot;Sprite/gotoAndPlay&quot;}}{{/crossLink}}
473	 * is called. Note that calling {{#crossLink &quot;Sprite/gotoAndPlay&quot;}}{{/crossLink}} or {{#crossLink &quot;Sprite/play&quot;}}{{/crossLink}}
474	 * will resume playback.
475	 * @method stop
476	 **/
477	p.stop = function() {
478		this.paused = true;
479	};
480
481	/**
482	 * Sets paused to false and plays the specified animation name, named frame, or frame number.
483	 * @method gotoAndPlay
484	 * @param {String|Number} frameOrAnimation The frame number or animation name that the playhead should move to
485	 * and begin playing.
486	 **/
487	p.gotoAndPlay = function(frameOrAnimation) {
488		this.paused = false;
489		this._skipAdvance = true;
490		this._goto(frameOrAnimation);
491	};
492
493	/**
494	 * Sets paused to true and seeks to the specified animation name, named frame, or frame number.
495	 * @method gotoAndStop
496	 * @param {String|Number} frameOrAnimation The frame number or animation name that the playhead should move to
497	 * and stop.
498	 **/
499	p.gotoAndStop = function(frameOrAnimation) {
500		this.paused = true;
501		this._goto(frameOrAnimation);
502	};
503
504	/**
505	 * Advances the playhead. This occurs automatically each tick by default.
506	 * @param [time] {Number} The amount of time in ms to advance by. Only applicable if framerate is set on the Sprite
507	 * or its SpriteSheet.
508	 * @method advance
509	*/
510	p.advance = function(time) {
511		var fps = this.framerate || this.spriteSheet.framerate;
512		var t = (fps &amp;&amp; time != null) ? time/(1000/fps) : 1;
513		this._normalizeFrame(t);
514	};
515	
516	/**
517	 * Returns a {{#crossLink &quot;Rectangle&quot;}}{{/crossLink}} instance defining the bounds of the current frame relative to
518	 * the origin. For example, a 90 x 70 frame with &lt;code&gt;regX=50&lt;/code&gt; and &lt;code&gt;regY=40&lt;/code&gt; would return a
519	 * rectangle with [x=-50, y=-40, width=90, height=70]. This ignores transformations on the display object.
520	 *
521	 * Also see the SpriteSheet {{#crossLink &quot;SpriteSheet/getFrameBounds&quot;}}{{/crossLink}} method.
522	 * @method getBounds
523	 * @return {Rectangle} A Rectangle instance. Returns null if the frame does not exist, or the image is not fully
524	 * loaded.
525	 **/
526	p.getBounds = function() {
527		// TODO: should this normalizeFrame?
528		return this.DisplayObject_getBounds() || this.spriteSheet.getFrameBounds(this.currentFrame, this._rectangle);
529	};
530
531	/**
532	 * Returns a clone of the Sprite instance. Note that the same SpriteSheet is shared between cloned
533	 * instances.
534	 * @method clone
535	 * @return {Sprite} a clone of the Sprite instance.
536	 **/
537	p.clone = function() {
538		return this._cloneProps(new Sprite(this.spriteSheet));
539	};
540
541	/**
542	 * Returns a string representation of this object.
543	 * @method toString
544	 * @return {String} a string representation of the instance.
545	 **/
546	p.toString = function() {
547		return &quot;[Sprite (name=&quot;+  this.name +&quot;)]&quot;;
548	};
549
550// private methods:
551	/**
552	 * @method _cloneProps
553	 * @param {Sprite} o
554	 * @return {Sprite} o
555	 * @protected
556	 **/
557	p._cloneProps = function(o) {
558		this.DisplayObject__cloneProps(o);
559		o.currentFrame = this.currentFrame;
560		o.currentAnimation = this.currentAnimation;
561		o.paused = this.paused;
562		o.currentAnimationFrame = this.currentAnimationFrame;
563		o.framerate = this.framerate;
564		
565		o._animation = this._animation;
566		o._currentFrame = this._currentFrame;
567		o._skipAdvance = this._skipAdvance;
568		return o;
569	};
570	
571	/**
572	 * Advances the &lt;code&gt;currentFrame&lt;/code&gt; if paused is not true. This is called automatically when the {{#crossLink &quot;Stage&quot;}}{{/crossLink}}
573	 * ticks.
574	 * @param {Object} evtObj An event object that will be dispatched to all tick listeners. This object is reused between dispatchers to reduce construction &amp; GC costs.
575	 * @protected
576	 * @method _tick
577	 **/
578	p._tick = function(evtObj) {
579		if (!this.paused) {
580			if (!this._skipAdvance) { this.advance(evtObj&amp;&amp;evtObj.delta); }
581			this._skipAdvance = false;
582		}
583		this.DisplayObject__tick(evtObj);
584	};
585
586
587	/**
588	 * Normalizes the current frame, advancing animations and dispatching callbacks as appropriate.
589	 * @protected
590	 * @method _normalizeFrame
591	 **/
592	p._normalizeFrame = function(frameDelta) {
593		frameDelta = frameDelta || 0;
594		var animation = this._animation;
595		var paused = this.paused;
596		var frame = this._currentFrame;
597		var l;
598		
599		if (animation) {
600			var speed = animation.speed || 1;
601			var animFrame = this.currentAnimationFrame;
602			l = animation.frames.length;
603			if (animFrame + frameDelta * speed &gt;= l) {
604				var next = animation.next;
605				if (this._dispatchAnimationEnd(animation, frame, paused, next, l - 1)) {
606					// something changed in the event stack, so we shouldn&#x27;t make any more changes here.
607					return;
608				} else if (next) {
609					// sequence. Automatically calls _normalizeFrame again with the remaining frames.
610					return this._goto(next, frameDelta - (l - animFrame) / speed);
611				} else {
612					// end.
613					this.paused = true;
614					animFrame = animation.frames.length - 1;
615				}
616			} else {
617				animFrame += frameDelta * speed;
618			}
619			this.currentAnimationFrame = animFrame;
620			this._currentFrame = animation.frames[animFrame | 0]
621		} else {
622			frame = (this._currentFrame += frameDelta);
623			l = this.spriteSheet.getNumFrames();
624			if (frame &gt;= l &amp;&amp; l &gt; 0) {
625				if (!this._dispatchAnimationEnd(animation, frame, paused, l - 1)) {
626					// looped.
627					if ((this._currentFrame -= l) &gt;= l) { return this._normalizeFrame(); }
628				}
629			}
630		}
631		frame = this._currentFrame | 0;
632		if (this.currentFrame != frame) {
633			this.currentFrame = frame;
634			this.dispatchEvent(&quot;change&quot;);
635		}
636	};
637
638	/**
639	 * Dispatches the &quot;animationend&quot; event. Returns true if a handler changed the animation (ex. calling {{#crossLink &quot;Sprite/stop&quot;}}{{/crossLink}},
640	 * {{#crossLink &quot;Sprite/gotoAndPlay&quot;}}{{/crossLink}}, etc.)
641	 * @property _dispatchAnimationEnd
642	 * @private
643	 * @type {Function}
644	 **/
645	p._dispatchAnimationEnd = function(animation, frame, paused, next, end) {
646		var name = animation ? animation.name : null;
647		if (this.hasEventListener(&quot;animationend&quot;)) {
648			var evt = new createjs.Event(&quot;animationend&quot;);
649			evt.name = name;
650			evt.next = next;
651			this.dispatchEvent(evt);
652		}
653		// did the animation get changed in the event stack?:
654		var changed = (this._animation != animation || this._currentFrame != frame);
655		// if the animation hasn&#x27;t changed, but the sprite was paused, then we want to stick to the last frame:
656		if (!changed &amp;&amp; !paused &amp;&amp; this.paused) { this.currentAnimationFrame = end; changed = true; }
657		return changed;
658	};
659
660	/**
661	 * Moves the playhead to the specified frame number or animation.
662	 * @method _goto
663	 * @param {String|Number} frameOrAnimation The frame number or animation that the playhead should move to.
664	 * @param {Boolean} [frame] The frame of the animation to go to. Defaults to 0.
665	 * @protected
666	 **/
667	p._goto = function(frameOrAnimation, frame) {
668		this.currentAnimationFrame = 0;
669		if (isNaN(frameOrAnimation)) {
670			var data = this.spriteSheet.getAnimation(frameOrAnimation);
671			if (data) {
672				this._animation = data;
673				this.currentAnimation = frameOrAnimation;
674				this._normalizeFrame(frame);
675			}
676		} else {
677			this.currentAnimation = this._animation = null;
678			this._currentFrame = frameOrAnimation;
679			this._normalizeFrame();
680		}
681	};
682
683
684	createjs.Sprite = createjs.promote(Sprite, &quot;DisplayObject&quot;);
685}());
686
687    </pre>
688</div>
689
690                    </div>
691                </div>
692            </div>
693        </div>
694    </div>
695</div>
696<script src="../assets/vendor/prettify/prettify-min.js"></script>
697<script>prettyPrint();</script>
698<script src="../assets/js/yui-prettify.js"></script>
699<script src="../assets/../api.js"></script>
700<script src="../assets/js/api-filter.js"></script>
701<script src="../assets/js/api-list.js"></script>
702<script src="../assets/js/api-search.js"></script>
703<script src="../assets/js/apidocs.js"></script>
704</body>
705</html>