Permalink
Browse files

Added error handling to SpriteSheet images

  • Loading branch information...
lannymcnie committed Nov 16, 2015
1 parent b764732 commit d742b8f56a46e16b2a63caf86ae5ccf9ec0b86b7
Showing with 36 additions and 2 deletions.
  1. +1 −0 VERSIONS.txt
  2. +8 −0 examples/SpriteSheet_simple.html
  3. +27 −2 src/easeljs/display/SpriteSheet.js
@@ -9,6 +9,7 @@ Version NEXT [Not Released]
- Changed SpriteSheet Array checks from instanceof to Array.isArray()
- Added StrokeDash support to SVGExporter
- Fixed issue with SVGExporter when the first lineTo has a zero-value for x or y
- Added image error handling to SpriteSheet
Version 0.8.1 [May 21, 2015]
@@ -31,6 +31,14 @@
}
});
// Events from SpriteSheet (not required for the demo)
spriteSheet.on("complete", function(event) {
console.log("Complete", event);
});
spriteSheet.on("error", function(event) {
console.log("Error", event);
});
var grant = new createjs.Sprite(spriteSheet, "run");
grant.x = stage.canvas.width / 2;
grant.y = 22;
@@ -349,6 +349,15 @@ this.createjs = this.createjs||{};
* @param {Object} frame The frame object that getFrame will return.
*/
/**
* Dispatched when an image encounters an error. A SpriteSheet will dispatch an error event for each image that
* encounters an error, and will still dispatch a {{#crossLink "SpriteSheet/complete:event"}}{{/crossLink}}
* event once all images are finished processing, even if an error is encountered.
* @event error
* @param {String} src The source of the image that failed to load.
* @since 0.8.2
*/
// getter / setters:
/**
@@ -485,7 +494,8 @@ this.createjs = this.createjs||{};
if (!img.getContext && !img.naturalWidth) {
this._loadCount++;
this.complete = false;
(function(o) { img.onload = function() { o._handleImageLoad(); } })(this);
(function(o, src) { img.onload = function() { o._handleImageLoad(src); } })(this, src);
(function(o, src) { img.onerror = function() { o._handleImageError(src); } })(this, src);
}
}
}
@@ -550,14 +560,29 @@ this.createjs = this.createjs||{};
* @method _handleImageLoad
* @protected
**/
p._handleImageLoad = function() {
p._handleImageLoad = function(src) {
if (--this._loadCount == 0) {
this._calculateFrames();
this.complete = true;
this.dispatchEvent("complete");
}
};
/**
* @method _handleImageError
* @protected
*/
p._handleImageError = function (src) {
var errorEvent = new createjs.Event("error");
errorEvent.src = src;
this.dispatchEvent(errorEvent);
// Complete is still dispatched.
if (--this._loadCount == 0) {
this.dispatchEvent("complete");
}
};
/**
* @method _calculateFrames
* @protected

0 comments on commit d742b8f

Please sign in to comment.