0

I am loading multiple xml files with URLLoader.

for (var i=0;i<xmlCount;i++) {
     loadXML(xmlFiles[i], i);
}

public function loadXML(req:String=null, _id:Number=0):void {
     var loader:URLLoader = new URLLoader();
     loader.addEventListener(ProgressEvent.PROGRESS, 
             function a(e:ProgressEvent) {XMLLoadProgress(e, _id);});
     loader.addEventListener(Event.COMPLETE, XMLLoadFinished);
     loader.load(new URLRequest(req));

}

private function XMLLoadProgress(e:ProgressEvent=null, _id:Number=0):void {
     dispatchEvent(new LoadingEvent(Model.LOADING_PROGRESS, _id, (e.bytesLoaded/e.bytesTotal)*100));
}

The problem is I think LOADING_PROGRESS gets dispatched after all the loading is done and each xml is loaded one by one not asynchronously.

How could I make it load asynchronously and also make it so progress event is called for each progress tick.

gok
  • 1,137
  • 1
  • 9
  • 30

2 Answers2

0

You can customize the URLLoader.

public function SequenceLoader extends URLLoader {
    private var index:int;

    public function SequenceLoader(index:int) {
        this.index = index;
    }
}

then in each loadXML, mark the loader:

public function loadXML(req:String=null, _id:Number=0):void {
     var loader:SequenceLoader = new SequenceLoader(_id);
     loader.addEventListener(ProgressEvent.PROGRESS, 
             function a(e:ProgressEvent) {XMLLoadProgress(e);});
     loader.addEventListener(Event.COMPLETE, XMLLoadFinished);
     loader.load(new URLRequest(req));
}

private function XMLLoadProgress(e:ProgressEvent=null):void {
   var loader:SequenceLoader  = e.target as SequenceLoader;
   var loaderIndex:int = loader.index;
  //do other stuff
}
jason
  • 1,621
  • 6
  • 21
  • 39
0

I'm guessing this only happens when viewing over a fast connection. Try viewing with a slow connection (Charles Proxy has the ability to artificially slow down your connection).

Dusty J
  • 721
  • 6
  • 12