Fix assets error handling
diff --git a/README.md b/README.md
index 7ea3633..f843912 100644
--- a/README.md
+++ b/README.md
@@ -217,6 +217,7 @@
- segmentStart
- config_ready (when initial config is done)
- data_ready (when all parts of the animation have been loaded)
+- data_failed (when part of the animation can not be loaded)
- loaded_images (when all image loads have either succeeded or errored)
- DOMLoaded (when elements have been added to the DOM)
- destroy
diff --git a/player/js/animation/AnimationItem.js b/player/js/animation/AnimationItem.js
index 4f604f5..beda2b6 100644
--- a/player/js/animation/AnimationItem.js
+++ b/player/js/animation/AnimationItem.js
@@ -82,7 +82,9 @@
this.fileName = params.path.substr(params.path.lastIndexOf('/')+1);
this.fileName = this.fileName.substr(0,this.fileName.lastIndexOf('.json'));
- assetLoader.load(params.path, this.configAnimation.bind(this));
+ assetLoader.load(params.path, this.configAnimation.bind(this), function() {
+ this.trigger('data_failed');
+ }.bind(this));
}
};
@@ -166,7 +168,9 @@
this.timeCompleted = segment.time * this.frameRate;
var segmentPath = this.path+this.fileName+'_' + this.segmentPos + '.json';
this.segmentPos += 1;
- assetLoader.load(segmentPath, this.includeLayers.bind(this));
+ assetLoader.load(segmentPath, this.includeLayers.bind(this), function() {
+ this.trigger('data_failed');
+ }.bind(this));
};
AnimationItem.prototype.loadSegments = function() {
diff --git a/player/js/utils/asset_loader.js b/player/js/utils/asset_loader.js
index 198732d..e003f12 100644
--- a/player/js/utils/asset_loader.js
+++ b/player/js/utils/asset_loader.js
@@ -10,7 +10,7 @@
}
}
- function loadAsset(path, callback, error) {
+ function loadAsset(path, callback, errorCallback) {
var response;
var xhr = new XMLHttpRequest();
xhr.open('GET', path, true);
@@ -27,8 +27,8 @@
response = formatResponse(xhr);
callback(response);
}catch(err){
- if(error_callback) {
- error_callback(err);
+ if(errorCallback) {
+ errorCallback(err);
}
}
}
@@ -38,4 +38,4 @@
return {
load: loadAsset
}
-}())
\ No newline at end of file
+}())