CreateJS / PreloadJS

PreloadJS makes preloading assets & getting aggregate progress events easier in JavaScript. It uses XHR2 when available, and falls back to tag-based loading when not.
http://createjs.com/
MIT License
2.87k stars 762 forks source link

preloadjs continue loading on error #241

Closed ramarro123 closed 7 years ago

ramarro123 commented 7 years ago

hello,

i am loading a big manifest of file on a queue, and i want to know if ti's possible to ignore 404 for certain file.

like game/lang/cn.json --> can be missing game/lang/en.json game/common/data.json game/specific/data.json --> can be missing

in that way i can keep the loading engine separated from the game logic, making it a component for my project.

at the moment, if one of the file is missing, preloadjs will just fail. if i set stopOnError, it affect all the files, not just some of them

regards

lannymcnie commented 7 years ago

The queue does not stop if it encounters an error unless you tell it to. You should still receive fileload events for all your other items, and a complete event for your queue.

Are you seeing something different?

ramarro123 commented 7 years ago

i am asking for something different, i think.

i want to block and throw error only on certain errors and ignore the others. if i do stoponerror of course, queue will stop on error :) if i don't set stop on error, then it won't stop on ANY error

i want to stop only on SOME error.

so basically, i want to set "stoponerror=false" (or true whatever) and set into the file "shouldstoponerror=true" (or false) that override the global queue way of handling things.

it's that possible?

lannymcnie commented 7 years ago

If you want to stop on specific items, I recommend using the error event, and inspecting which item failed. You can then stop the queue if a certain item fails:

var queue = new createjs.LoadQueue();
queue.on("error", function(event) {
    var item = event.data,
        id = item.id;
    switch (id) {
        case "img2":
            queue.close(); // No more loading or events
            break;
    }
}
queue.loadManifest([
    {id: "img1", "path/to/image1.jpg"},
    {id: "img2", "path/to/image2.jpg"}, // 404 or something
    {id: "img3", "path/to/image3.jpg"}
]);

This is just pseudo-code (not tested), but you get the idea. If you want the queue to stop under specific conditions, this is the best way (rather than some rarely-used API like adding stopOnError to load items.

Hope that makes sense.