From dfde054991d2a78aa1f53c95b096e693b2f84a1f Mon Sep 17 00:00:00 2001 From: bibixx Date: Sun, 10 Jan 2021 21:37:54 +0100 Subject: [PATCH] feat(loader): add check for asset loading error Added check to CreateJS.LoadQueue to provide user with more user-friendly error in case one of the Adobe Animate's assets aren't loaded properly re #41 --- src/AnimateCC/AnimateCC.tsx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/AnimateCC/AnimateCC.tsx b/src/AnimateCC/AnimateCC.tsx index 7a39826..5b71387 100644 --- a/src/AnimateCC/AnimateCC.tsx +++ b/src/AnimateCC/AnimateCC.tsx @@ -48,6 +48,7 @@ export class AnimateCC extends React.Component { const loader = new CreateJS.LoadQueue(false); loader.addEventListener('fileload', (evt) => { this.handleFileLoad(evt as createjs.Event, composition); }); loader.addEventListener('complete', (evt) => { this.handleComplete(evt as createjs.Event, composition); }); + loader.addEventListener('error', (evt) => { this.handleFileError(evt as createjs.ErrorEvent); }); loader.loadManifest(manifest); if (manifest.filter(({ type }) => type === 'image').length === 0) { @@ -85,7 +86,21 @@ export class AnimateCC extends React.Component { this.startAnimation(); }; + private handleFileError = (evt: createjs.ErrorEvent) => { + if (evt.title === 'FILE_LOAD_ERROR') { + const { src } = evt.data as { src: string }; + + log(`Asset ${src} failed to load`); + this.setState({ error: true }); + } + }; + private handleComplete = (evt: createjs.Event|null, composition: Composition) => { + const { error } = this.state; + if (error) { + return; + } + const { animationName, paused, getAnimationObject, } = this.props;