Multiple URLLoader.load() calls?

Please tell me it doesn't work.

Page 1 of 1

0 Replies - 2354 Views - Last Post: 16 September 2009 - 06:29 PM

#1 Ter13  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 30
  • Joined: 05-September 09

Multiple URLLoader.load() calls?

Posted 16 September 2009 - 06:29 PM

Well, I just got done writing a queue system for my streaming external XML/Image/Swf file loader for my flash application...

And then it hit me. If you call URLLoader.load() multiple times with different files, does it queue up the downloads itself?

Seems to me that it might work, but I'm really hoping it doesn't, because I'll be pissed if it does... I spent an hour writing a one-stop-shop file streamer and processing class...

package  {
	
	public class ExternalLoader {
		
		// Constants:
		// Public Properties:
		var xmlLoader:URLLoader;
		var imgLoader:Loader;
		var frequest:URLRequest;
		var queue:Array = new Array();
		var isRunning:Boolean;
		// Private Properties:
	
		// Initialization:
		public function ExternalLoader()
		{
			xmlLoader = new URLLoader();
			imgLoader = new Loader();
			function completeEvent(ent:Event):void
			{
				moveQueue(ent);
			}
			xmlLoader.dataFormat = URLLoaderDataForma.TEXT;
			xmlLoader.addEventListener(EVENT.COMPLETE,compEvent);
			imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,compEvent);
			isRunning = false;
		}
		
		public function addImageRequest(fname:String,onloadObj:Object,onloadFunc:Function)
		{
			queue.push("resource");
			queue.push(fname);
			queue.push(onloadObj);
			queue.push(onloadFunc);
		}
		
		public function addXMLRequest(fname:String,onloadObj:Object,onloadFunc:Function)
		{
			queue.push("text");
			queue.push(fname);
			queue.push(onloadObj);
			queue.push(onloadFunc);
		}
		// Public Methods:
		
		public function processQueue():void
		{
			if(isRunning==false&&queue.length>0)
			{
				isRunning = true;
				fType:String = queue[0];
				fName:String = queue[1];
				frequest = new URLRequest(fName);
				if(fType=="resource")
				{
					imgLoader.load(this.frequest);
				}
				else if(fType=="text")
				{
					xmlLoader.load(this.frequest);
				}
			}
		}
		
		public function moveQueue(ent:Event)
		{
			var fType:String = queue.shift();
			var fName:String = queue.shift();
			var cObj:Object = queue.shift();
			var cFunc:Function = queue.shift();
			if(ftype=="resource")
			{
				cFunc.call(cObj,ent);
			}
			else if(ftype=="text")
			{
				var fXML:XML = xmlloader.data;
				cFunc.call(cObj,fXML);
			}
			isRunning = false;
			processQueue();
		}
		// Protected Methods:
	}
	
}



Might still have some bugs... Haven't tested it yet, but I'm confident in AS3. No issues with figuring out what I failed at.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1