Open xpol opened 7 years ago
Typically we recreate queues, but I can see how issues surrounding caching could make reuse more useful.
I got caught out with this - complete firing when some resources not loaded.
var myLoadQueue=null;
var myManifest=[];
myManifest.push({src:'sprite0.png',id:'sprite0'});
myManifest.push({src:'sprite1.png',id:'sprite1'});
myManifest.push({src:'sprite2.png',id:'sprite2'});
function load(){
myLoadQueue=new createjs.LoadQueue(false);
myLoadQueue.addEventListener('complete',setupAssets);
myLoadQueue.addEventListener('error',gotError);
myLoadQueue.loadManifest(myManifest,true,resFolder);
}
function gotError(){
myLoadQueue.removeEventListener('complete',setupAssets);
myLoadQueue.removeEventListener('error',gotError);
myLoadQueue.destroy();
myLoadQueue=null;
tryTimes--;
if(tryTimes>0){
console.log('Load Error - retrying');
load();
}else{
console.log('Load Error - giving up');
}
}
function setupAssets(){
}
If load fails the first time, then it seems to ignore that file on the second try and fire the complete event when the others have loaded.
I got it to work as intended by putting the manifest inside the load function:
function load(){
var myManifest=[];
myManifest.push({src:'sprite0.png',id:'sprite0'});
myManifest.push({src:'sprite1.png',id:'sprite1'});
myManifest.push({src:'sprite2.png',id:'sprite2'});
myLoadQueue=new createjs.LoadQueue(false);
myLoadQueue.addEventListener('complete',setupAssets);
myLoadQueue.addEventListener('error',gotError);
myLoadQueue.loadManifest(myManifest,true,resFolder);
}
I have a single page application (SPA) use PreloadJS for resource loading.
I have different screens (pages) in my SPA (have different url using react-router). I need load resources for each view when user navigate to. And if previous loading is not complete I need just stop all loading before new loading.
Should I create a new LoadQueue for each loading process or reuse the LoadQueue?
I first tried to reuse the queue:
But it sometimes fires 'complete' when some resources not loaded.
Then I tried:
My question is which is the best practice to load different set of resources, create a new LoadQueue for each set or reuse one single LoadQueue? If reuse is OK, how to correct reset LoadQueue for next loading request.