I'm using createJS - preloadJS and ES6 along with Babel and webpack.
const files = [{ src: 'characterSprite.png', id: 'characterSprite' }];
const Loader = new createjs.LoadQueue(false);
Loader.loadManifest(files, true, 'img/');
export default Loader;
What I want to achieve is in preload.js to load all the images, and in other files (eg. hero.js) to do something like:
import Loader from './loader';
Loader.getResult('characterSprite');
The thing is that when I call .getResult()
on loader, the loader has not finished preloading so it returns undefined
.
I can check when loader is finished by using:
Loader.addEventListener('complete', () => console.log('loader has finished');
My question is if I can export the module only if the loader has finished?
Is there a better way of doing this?