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 761 forks source link

[Question] How to get the number of items in manifest before they are loaded? #228

Closed ppisecky closed 7 years ago

ppisecky commented 7 years ago

This is an edge use-case but is there currently a way to get the number of items in an external manifest before they are loaded?

I tried to load assets via an external manifest and get their number in a fileload event callback for the purposes of displaying progress in the form remaining/allFiles. The problem is that the event triggers last for the manifest itself (I assume this has something to do with the fact that it is only considered loaded once its contents have been loaded):

     //Example of an attempt
     var fileTypes = createjs.LoadQueue;
     preload.on("fileload", function (e) {
          var type = e.item.type;
          if (type == fileTypes.MANIFEST) {
              //Last to load
              count = e.loader._manifestQueue._numItems;
          }
          if (type == fileTypes.CSS || type == fileTypes.JAVASCRIPT) {
              document.body.appendChild(e.result);
          }
      });
      preload.loadManifest({ src: manifestSrc, type: "manifest" });

I wasn't able to succesfully solve this via the progress event either. Is there currently a way to retreive the number of files in manifests before they are added to a queue/loaded? Thanks in advance for advice

lannymcnie commented 7 years ago

Sorry for the delayed response. The progress on the LoadQueue falls back to the number of items when there is no progress available on specific items (usually when tag-loading).

You can refer to the internal parameters

Open to an alternate approach. Is there value in getting a numFiles / numFilesComplete or something (my poor naming aside)?

Closing for now. Feel free to reopen if there is a specific issue, or you have a proposal on an enhancement.