Updated createjs.

This commit is contained in:
Scott Erickson 2014-03-22 09:40:23 -07:00
parent 5141873725
commit 643140fc98
3 changed files with 517 additions and 748 deletions

View file

@ -5300,7 +5300,7 @@ var p = DisplayObject.prototype = new createjs.EventDispatcher();
* event.
* @property onTick
* @type {Function}
* @deprecatedtick
* @deprecated Use addEventListener and the "tick" event.
*/
/**
@ -5768,7 +5768,7 @@ var p = DisplayObject.prototype = new createjs.EventDispatcher();
* be used to transform positions between coordinate spaces, such as with {{#crossLink "DisplayObject/localToGlobal"}}{{/crossLink}}
* and {{#crossLink "DisplayObject/globalToLocal"}}{{/crossLink}}.
* @method getConcatenatedMatrix
* @param {Matrix2D} [mtx] A {{#crossLink "Matrix2D"}}{{/crossLink}} object to populate with the calculated values.
* @param {Matrix2D} [matrix] A {{#crossLink "Matrix2D"}}{{/crossLink}} object to populate with the calculated values.
* If null, a new Matrix2D object is returned.
* @return {Matrix2D} a concatenated Matrix2D object representing the combined transform of the display object and
* all of its parent Containers up to the highest level ancestor (usually the {{#crossLink "Stage"}}{{/crossLink}}).
@ -7012,14 +7012,6 @@ var p = Stage.prototype = new createjs.Container();
* @default false
**/
p.mouseMoveOutside = false;
// TODO: deprecated.
/**
* Replaced by {{#crossLink "Stage/relayEventsTo"}}{{/crossLink}}.
* @property nextStage
* @type Stage
* @deprecated Use relayEventsTo instead.
**/
/**
* The hitArea property is not supported for Stage.
@ -9794,18 +9786,17 @@ var p = SpriteSheetBuilder.prototype = new createjs.EventDispatcher;
* source to draw to the frame. If not specified, it will look for a <code>getBounds</code> method, bounds property,
* or <code>nominalBounds</code> property on the source to use. If one is not found, the frame will be skipped.
* @param {Number} [scale=1] Optional. The scale to draw this frame at. Default is 1.
* @param {Function} [setupFunction] Optional. A function to call immediately before drawing this frame.
* @param {Array} [setupParams] Parameters to pass to the setup function.
* @param {Object} [setupScope] The scope to call the setupFunction in.
* @param {Function} [setupFunction] A function to call immediately before drawing this frame. It will be called with two parameters: the source, and setupData.
* @param {Object} [setupData] Arbitrary setup data to pass to setupFunction as the second parameter.
* @return {Number} The index of the frame that was just added, or null if a sourceRect could not be determined.
**/
p.addFrame = function(source, sourceRect, scale, setupFunction, setupParams, setupScope) {
p.addFrame = function(source, sourceRect, scale, setupFunction, setupData) {
if (this._data) { throw SpriteSheetBuilder.ERR_RUNNING; }
var rect = sourceRect||source.bounds||source.nominalBounds;
if (!rect&&source.getBounds) { rect = source.getBounds(); }
if (!rect) { return null; }
scale = scale||1;
return this._frames.push({source:source, sourceRect:rect, scale:scale, funct:setupFunction, params:setupParams, scope:setupScope, index:this._frames.length, height:rect.height*scale})-1;
return this._frames.push({source:source, sourceRect:rect, scale:scale, funct:setupFunction, data:setupData, index:this._frames.length, height:rect.height*scale})-1;
};
/**
@ -9825,37 +9816,35 @@ var p = SpriteSheetBuilder.prototype = new createjs.EventDispatcher;
};
/**
* This will take a MovieClip, and add its frames and labels to this builder. Labels will be added as an animation
* This will take a MovieClip instance, and add its frames and labels to this builder. Labels will be added as an animation
* running from the label index to the next label. For example, if there is a label named "foo" at frame 0 and a label
* named "bar" at frame 10, in a MovieClip with 15 frames, it will add an animation named "foo" that runs from frame
* index 0 to 9, and an animation named "bar" that runs from frame index 10 to 14.
*
* Note that this will iterate through the full MovieClip with actionsEnabled set to false, ending on the last frame.
* @method addMovieClip
* @param {MovieClip} source The source MovieClip to add to the sprite sheet.
* @param {MovieClip} source The source MovieClip instance to add to the sprite sheet.
* @param {Rectangle} [sourceRect] A {{#crossLink "Rectangle"}}{{/crossLink}} defining the portion of the source to
* draw to the frame. If not specified, it will look for a <code>getBounds</code> method, <code>frameBounds</code>
* Array, <code>bounds</code> property, or <code>nominalBounds</code> property on the source to use. If one is not
* found, the MovieClip will be skipped.
* @param {Number} [scale=1] The scale to draw the movie clip at.
* @param {Function} [setupFunction] A function to call immediately before drawing each frame. It will be called with three parameters: the source, setupData, and the frame index.
* @param {Object} [setupData] Arbitrary setup data to pass to setupFunction as the second parameter.
* @param {Function} [labelFunction] This method will be called for each movieclip label that is added with four parameters: the label name, the source movieclip instance, the starting frame index (in the movieclip timeline) and the end index. It must return a new name for the label/animation, or false to exclude the label.
**/
p.addMovieClip = function(source, sourceRect, scale) {
p.addMovieClip = function(source, sourceRect, scale, setupFunction, setupData, labelFunction) {
if (this._data) { throw SpriteSheetBuilder.ERR_RUNNING; }
var rects = source.frameBounds;
var rect = sourceRect||source.bounds||source.nominalBounds;
if (!rect&&source.getBounds) { rect = source.getBounds(); }
if (!rect && !rects) { return null; }
if (!rect && !rects) { return; }
var baseFrameIndex = this._frames.length;
var i, l, baseFrameIndex = this._frames.length;
var duration = source.timeline.duration;
for (var i=0; i<duration; i++) {
for (i=0; i<duration; i++) {
var r = (rects&&rects[i]) ? rects[i] : rect;
this.addFrame(source, r, scale, function(frame) {
var ae = this.actionsEnabled;
this.actionsEnabled = false;
this.gotoAndStop(frame);
this.actionsEnabled = ae;
}, [i], source);
this.addFrame(source, r, scale, this._setupMovieClipFrame, {i:i, f:setupFunction, d:setupData});
}
var labels = source.timeline._labels;
var lbls = [];
@ -9864,12 +9853,16 @@ var p = SpriteSheetBuilder.prototype = new createjs.EventDispatcher;
}
if (lbls.length) {
lbls.sort(function(a,b){ return a.index-b.index; });
for (var i=0,l=lbls.length; i<l; i++) {
for (i=0,l=lbls.length; i<l; i++) {
var label = lbls[i].label;
var start = baseFrameIndex+lbls[i].index;
var end = baseFrameIndex+((i == l-1) ? duration : lbls[i+1].index);
var frames = [];
for (var j=start; j<end; j++) { frames.push(j); }
if (labelFunction) {
label = labelFunction(label, source, start, end);
if (!label) { continue; }
}
this.addAnimation(label, frames, true); // for now, this loops all animations.
}
}
@ -9969,6 +9962,20 @@ var p = SpriteSheetBuilder.prototype = new createjs.EventDispatcher;
}
}
};
/**
* @method _setupMovieClipFrame
* @protected
* @return {Number} The width & height of the row.
**/
p._setupMovieClipFrame = function(source, data) {
var ae = source.actionsEnabled;
source.actionsEnabled = false;
source.gotoAndStop(data.i);
source.actionsEnabled = ae;
data.f&&data.f(source, data.d, data.i);
};
/**
* @method _getSize
@ -10067,7 +10074,7 @@ var p = SpriteSheetBuilder.prototype = new createjs.EventDispatcher;
var sourceRect = frame.sourceRect;
var canvas = this._data.images[frame.img];
var ctx = canvas.getContext("2d");
frame.funct&&frame.funct.apply(frame.scope, frame.params);
frame.funct&&frame.funct(frame.source, frame.data);
ctx.save();
ctx.beginPath();
ctx.rect(rect.x, rect.y, rect.width, rect.height);

View file

@ -27,7 +27,7 @@ this.createjs = this.createjs||{};
* @type String
* @static
**/
s.buildDate = /*date*/"Wed, 18 Dec 2013 23:28:57 GMT"; // injected by build process
s.buildDate = /*date*/"Thu, 06 Mar 2014 22:58:10 GMT"; // injected by build process
})();
/*
@ -1745,8 +1745,30 @@ TODO: WINDOWS ISSUES
/**
* Ensure loaded scripts "complete" in the order they are specified. Loaded scripts are added to the document head
* once they are loaded. Note that scripts loaded via tags will load one-at-a-time when this property is `true`.
* load one at a time
* once they are loaded. Scripts loaded via tags will load one-at-a-time when this property is `true`, whereas
* scripts loaded using XHR can load in any order, but will "finish" and be added to the document in the order
* specified.
*
* Any items can be set to load in order by setting the `maintainOrder` property on the load item, or by ensuring
* that only one connection can be open at a time using {{#crossLink "LoadQueue/setMaxConnections"}}{{/crossLink}}.
* Note that when the `maintainScriptOrder` property is set to `true`, scripts items are automatically set to
* `maintainOrder=true`, and changing the `maintainScriptOrder` to `false` during a load will not change items
* already in a queue.
*
* <h4>Example</h4>
*
* var queue = new createjs.LoadQueue();
* queue.setMaxConnections(3); // Set a higher number to load multiple items at once
* queue.maintainScriptOrder = true; // Ensure scripts are loaded in order
* queue.loadManifest([
* "script1.js",
* "script2.js",
* "image.png", // Load any time
* {src: "image2.png", maintainOrder: true} // Will wait for script2.js
* "image3.png",
* "script3.js" // Will wait for image2.png before loading (or completing when loading with XHR)
* ]);
*
* @property maintainScriptOrder
* @type {Boolean}
* @default true
@ -2247,6 +2269,11 @@ TODO: WINDOWS ISSUES
* of types using the extension. Supported types are defined on LoadQueue, such as <code>LoadQueue.IMAGE</code>.
* It is recommended that a type is specified when a non-standard file URI (such as a php script) us used.</li>
* <li>id: A string identifier which can be used to reference the loaded object.</li>
* <li>maintainOrder: Set to `true` to ensure this asset loads in the order defined in the manifest. This
* will happen when the max connections has been set above 1 (using {{#crossLink "LoadQueue/setMaxConnections"}}{{/crossLink}}),
* and will only affect other assets also defined as `maintainOrder`. Everything else will finish as it is
* loaded. Ordered items are combined with script tags loading in order when {{#crossLink "LoadQueue/maintainScriptOrder:property"}}{{/crossLink}}
* is set to `true`.</li>
* <li>callback: Optional, used for JSONP requests, to define what method to call when the JSONP is loaded.</li>
* <li>data: An arbitrary data object, which is included with the loaded object</li>
* <li>method: used to define if this request uses GET or POST when sending data to the server. The default
@ -2314,9 +2341,14 @@ TODO: WINDOWS ISSUES
* <li>src: The source of the file that is being loaded. This property is <b>required</b>. The source can
* either be a string (recommended), or an HTML tag.</li>
* <li>type: The type of file that will be loaded (image, sound, json, etc). PreloadJS does auto-detection
* of types using the extension. Supported types are defined on LoadQueue, such as <code>LoadQueue.IMAGE</code>.
* of types using the extension. Supported types are defined on LoadQueue, such as {{#crossLink "LoadQueue/IMAGE:property"}}{{/crossLink}}.
* It is recommended that a type is specified when a non-standard file URI (such as a php script) us used.</li>
* <li>id: A string identifier which can be used to reference the loaded object.</li>
* <li>maintainOrder: Set to `true` to ensure this asset loads in the order defined in the manifest. This
* will happen when the max connections has been set above 1 (using {{#crossLink "LoadQueue/setMaxConnections"}}{{/crossLink}}),
* and will only affect other assets also defined as `maintainOrder`. Everything else will finish as it is
* loaded. Ordered items are combined with script tags loading in order when {{#crossLink "LoadQueue/maintainScriptOrder:property"}}{{/crossLink}}
* is set to `true`.</li>
* <li>callback: Optional, used for JSONP requests, to define what method to call when the JSONP is loaded.</li>
* <li>data: An arbitrary data object, which is included with the loaded object</li>
* <li>method: used to define if this request uses GET or POST when sending data to the server. The default
@ -2499,6 +2531,7 @@ TODO: WINDOWS ISSUES
if (item == null) { return; } // Sometimes plugins or types should be skipped.
var loader = this._createLoader(item);
if (loader != null) {
item._loader = loader;
this._loadQueue.push(loader);
this._loadQueueBackup.push(loader);
@ -2506,9 +2539,11 @@ TODO: WINDOWS ISSUES
this._updateProgress();
// Only worry about script order when using XHR to load scripts. Tags are only loading one at a time.
if (this.maintainScriptOrder
if ((this.maintainScriptOrder
&& item.type == createjs.LoadQueue.JAVASCRIPT
&& loader instanceof createjs.XHRLoader) {
//&& loader instanceof createjs.XHRLoader //NOTE: Have to track all JS files this way
)
|| item.maintainOrder === true) {
this._scriptOrder.push(item);
this._loadedScripts.push(null);
}
@ -2717,13 +2752,9 @@ TODO: WINDOWS ISSUES
if (this._currentLoads.length >= this._maxConnections) { break; }
var loader = this._loadQueue[i];
// Determine if we should be only loading one at a time:
if (this.maintainScriptOrder
&& loader instanceof createjs.TagLoader
&& loader.getItem().type == createjs.LoadQueue.JAVASCRIPT) {
if (this._currentlyLoadingScript) { continue; } // Later items in the queue might not be scripts.
this._currentlyLoadingScript = true;
}
// Determine if we should be only loading one tag-script at a time:
// Note: maintainOrder items don't do anything here because we can hold onto their loaded value
if (!this._canStartLoad(loader)) { continue; }
this._loadQueue.splice(i, 1);
i--;
this._loadItem(loader);
@ -2755,6 +2786,8 @@ TODO: WINDOWS ISSUES
p._handleFileError = function(event) {
var loader = event.target;
this._numItemsLoaded++;
this._finishOrderedItem(loader, true);
this._updateProgress();
var newEvent = new createjs.Event("error");
@ -2787,47 +2820,43 @@ TODO: WINDOWS ISSUES
this._loadedRawResults[item.id] = loader.getResult(true);
}
// Clean up the load item
this._removeLoadItem(loader);
// Ensure that script loading happens in the right order.
if (this.maintainScriptOrder && item.type == createjs.LoadQueue.JAVASCRIPT) {
if (loader instanceof createjs.TagLoader) {
this._currentlyLoadingScript = false;
} else {
this._loadedScripts[createjs.indexOf(this._scriptOrder, item)] = item;
this._checkScriptLoadOrder(loader);
return;
}
if (!this._finishOrderedItem(loader)) {
// The item was NOT managed, so process it now
this._processFinishedLoad(item, loader);
}
// Clean up the load item
delete item._loadAsJSONP;
// If the item was a manifest, then
if (item.type == createjs.LoadQueue.MANIFEST) {
var result = loader.getResult();
if (result != null && result.manifest !== undefined) {
this.loadManifest(result, true);
}
}
this._processFinishedLoad(item, loader);
};
/**
* @method _processFinishedLoad
* @param {Object} item
* Flag an item as finished. If the item's order is being managed, then set it up to finish
* @method _finishOrderedItem
* @param {AbstractLoader} loader
* @protected
* @return {Boolean} If the item's order is being managed. This allows the caller to take an alternate
* behaviour if it is.
* @private
*/
p._processFinishedLoad = function(item, loader) {
// Old handleFileTagComplete follows here.
this._numItemsLoaded++;
p._finishOrderedItem = function(loader, loadFailed) {
var item = loader.getItem();
this._updateProgress();
this._sendFileComplete(item, loader);
if ((this.maintainScriptOrder && item.type == createjs.LoadQueue.JAVASCRIPT)
|| item.maintainOrder) {
this._loadNext();
//TODO: Evaluate removal of the _currentlyLoadingScript
if (loader instanceof createjs.TagLoader && item.type == createjs.LoadQueue.JAVASCRIPT) {
this._currentlyLoadingScript = false;
}
var index = createjs.indexOf(this._scriptOrder, item);
if (index == -1) { return false; } // This loader no longer exists
this._loadedScripts[index] = (loadFailed === true) ? true : item;
this._checkScriptLoadOrder();
return true;
}
return false;
};
/**
@ -2845,17 +2874,68 @@ TODO: WINDOWS ISSUES
for (var i=0;i<l;i++) {
var item = this._loadedScripts[i];
if (item === null) { break; } // This is still loading. Do not process further.
if (item === true) { continue; } // This has completed, and been processed. Move on.
if (item === true) { continue; } // This has completed, and been processed. Move on.
// Append script tags to the head automatically. Tags do this in the loader, but XHR scripts have to maintain order.
var loadItem = this._loadedResults[item.id];
(document.body || document.getElementsByTagName("body")[0]).appendChild(loadItem);
if (item.type == createjs.LoadQueue.JAVASCRIPT) {
// Append script tags to the head automatically. Tags do this in the loader, but XHR scripts have to maintain order.
(document.body || document.getElementsByTagName("body")[0]).appendChild(loadItem);
}
this._processFinishedLoad(item);
var loader = item._loader;
this._processFinishedLoad(item, loader);
this._loadedScripts[i] = true;
}
};
/**
* @method _processFinishedLoad
* @param {Object} item
* @param {AbstractLoader} loader
* @protected
*/
p._processFinishedLoad = function(item, loader) {
// If the item was a manifest, then queue it up!
if (item.type == createjs.LoadQueue.MANIFEST) {
var result = loader.getResult();
if (result != null && result.manifest !== undefined) {
this.loadManifest(result, true);
}
}
this._numItemsLoaded++;
this._updateProgress();
this._sendFileComplete(item, loader);
this._loadNext();
};
/**
* Ensure items with `maintainOrder=true` that are before the specified item have loaded. This only applies to
* JavaScript items that are being loaded with a TagLoader, since they have to be loaded and completed <strong>before</strong>
* the script can even be started, since it exist in the DOM while loading.
* @method _canStartLoad
* @param {XHRLoader|TagLoader} loader The loader for the item
* @return {Boolean} Whether the item can start a load or not.
* @private
*/
p._canStartLoad = function(loader) {
if (!this.maintainScriptOrder || loader instanceof createjs.XHRLoader) { return true; }
var item = loader.getItem();
if (item.type != createjs.LoadQueue.JAVASCRIPT) { return true; }
if (this._currentlyLoadingScript) { return false; }
var index = this._scriptOrder.indexOf(item);
var i = 0;
while (i < index) {
var checkItem = this._loadedScripts[i];
if (checkItem == null) { return false; }
i++;
}
this._currentlyLoadingScript = true;
return true;
};
/**
* A load item is completed or was canceled, and needs to be removed from the LoadQueue.
* @method _removeLoadItem
@ -2863,6 +2943,10 @@ TODO: WINDOWS ISSUES
* @private
*/
p._removeLoadItem = function(loader) {
var item = loader.getItem();
delete item._loader;
delete item._loadAsJSONP;
var l = this._currentLoads.length;
for (var i=0;i<l;i++) {
if (this._currentLoads[i] == loader) {
@ -3058,7 +3142,7 @@ TODO: WINDOWS ISSUES
item.completeHandler(event);
}
this.hasEventListener("fileload") && this.dispatchEvent(event)
this.hasEventListener("fileload") && this.dispatchEvent(event);
};
/**

File diff suppressed because it is too large Load diff