Batch loading several XML files

I had a problem to load several XML files and wait while it complete loads. This class help me to solve this problem.


package
{
    import flash.events.Event;
    import flash.events.EventDispatcher;
    import flash.events.IEventDispatcher;
    import flash.events.ProgressEvent;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    
    [Event(name="complete", type="flash.events.Event")]
    [Event(name="progress", type="flash.events.ProgressEvent")]
    
    public class BatchLoader extends EventDispatcher
    {
        private var _files:Array = new Array;
        private var _loaders:Array = new Array;
        private var _done:Number = 0;
        private var _total:Number = 0;
        
        public function BatchLoader(target:IEventDispatcher=null)
        {
            super(target);
        }
        
        public function load():void
        {
            this._total= this._loaders.length;
            
            for (var index:int = 0; index < this._total; index++) {
                this._loaders[index].load(new URLRequest(this._files[index]));
            }
        }
        
        public function addFile(url:String, callback:Object, context:Object):void
        {
            this._files.push(url);
            
            var urlLoader:URLLoader = new URLLoader();
            urlLoader.addEventListener(Event.COMPLETE, function(e:Event):void {
                callback(new XML(e.target.data), context);
                _done++;
                if (_done == _total) {
                    dispatchEvent(new Event(Event.COMPLETE));
                }
            });
            this._loaders.push(urlLoader);
        }
    }
}

usage:


var _batchLoader:BatchLoader = new BatchLoader;
    this._batchLoader.addEventListener(Event.COMPLETE, _xmlLoadingComplete);
    this._batchLoader.addFile(value.catalogUrl, function(data:XML, _this:Object):void {
        _this._setCatalog(data);
    }, this);
    this._batchLoader.addFile(value.additionalItemsUrl, function(data:XML, _this:Object):void {
        _this._setAdditional(data);
    }, this);
    this._batchLoader.load();