A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: donwloading multiple images/files

  1. #1
    Senior Member
    Join Date
    Mar 2003
    Location
    Canada
    Posts
    166

    donwloading multiple images/files

    Lets say I'm downloading multiple files like this:

    var myLoader:Loader = new Loader();
    myLoader.contentLoaderInfo.addEventListener(Progre ssEvent.PROGRESS, onProgressStatus);
    myLoader.contentLoaderInfo.addEventListener(Event. COMPLETE, onLoaderReady);

    for(var i =0; i < 100;i++){
    var fileRequest:URLRequest = new URLRequest(aImages[i].url);
    myLoader.load(fileRequest);

    public function
    onProgressStatus(e:ProgressEvent) {
    // this is where progress will be monitored
    trace(e.bytesLoaded, e.bytesTotal);
    }

    public function onLoaderReady(e:Event) {
    // the image is now loaded, so let's add it to the display tree!
    someMC.addChild(myLoader);
    }
    Now the question is how do I tell which image has loaded in the onLoaderReader function, is there a way to identify the image loaded?

  2. #2
    Junior Member
    Join Date
    Jul 2009
    Posts
    19
    dont do it like so..
    load one image and when its loaded call load again on the next image, until all are loaded

  3. #3
    Senior Member
    Join Date
    Mar 2003
    Location
    Canada
    Posts
    166
    ny other suggestions?

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    That code won't even compile. You have an unclosed for loop.

    I'd suggest using a package that's already developed for loading a lot of resources, such as bulkloader or queueloader. But if you don't want to deal with those, you'll need to have a new Loader for each resource, or do them one at a time. Assuming you want to load them all at once, you can write a function to create a new loader and kick it off.

    Code:
    public function loadSomething(url:String):void{
      var myLoader:Loader = new Loader();
      myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressStatus);
      myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderReady);
      var fileRequest:URLRequest = new URLRequest(url);
      myLoader.load(fileRequest);
    }
    
    public function  onProgressStatus(e:ProgressEvent) {
      // this is where progress will be monitored
      trace(e.bytesLoaded, e.bytesTotal);
    }
    
    public function onLoaderReady(e:Event) {
      // the image is now loaded, so let's add it to the display tree!
      someMC.addChild(LoaderInfo(e.currentTarget).loader);
    } 
    
    for(var i =0; i < 100;i++){
      loadSomething(aImages[i].url);
    }

  5. #5
    Member
    Join Date
    Nov 2002
    Posts
    43
    I try to use Bulkloader to preload images to the application.
    Now I have to be absolutely sure that all images are in place or application will not even start working. I would prefer to deal with missing images in the code, and not break whole application.

    Is there a way to launch COMPLETE event if not all assets are loaded? I cannot find it.

  6. #6
    Member
    Join Date
    Nov 2002
    Posts
    43
    Found it.
    BulkLoader.as in _onItemError() calls only function _removeFromConnections(item).
    I added _removeFromItems(item), now COMPLETE event is discharged when all existing images are loaded.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center