PDA

View Full Version : URLRequest more than one at a time



snozbunny
January 8th, 2009, 02:01 PM
Hi, I'm trying to get more than one bitmap to load before the complete event handler is called. Does anyone know a way to queue up multiple requests at once?

Possibly a bitmap loader class?

Thx in advance! :thumb:

irrationalistic
January 8th, 2009, 02:46 PM
I think you can only have one "complete" event per loader, so my suggestion would be to create an array which has the URL of each element you wish to load. Then create a function called loadNext() which will pop() the first element from the array and set up the loaders. In your onComplete, simply call loadNext() to move to the next item in the array. At the top of loadNext you want to do a check on the length of your array to see if you have no more items to load. If that is the case, then all your files are complete and you can move on with your SWF!

If that is too confusing, I can try to post some snippets for you.

Good Luck!

snozbunny
January 8th, 2009, 03:00 PM
That's exactly what I started building. Thanks for the advice, I didn't think to loop the loader function. Thank you for the help!

[EDIT]

I'm guessing I need to pass along a object name for each one. That's going to complicated things considerably. Any idea how to get the length of one part of a multidimensional array?

snozbunny
January 8th, 2009, 05:10 PM
I've gotten this far but now the pain is getting each url request into a new element I can call on at a moment's notice.. Any suggestions?



package components.flv_player
{
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.display.Bitmap;

public class pre_load extends Loader
{
private var request:Array = new Array(new Array(), new Array());
private var i:uint = 0;

public function queue(objectName:String, url:String):void
{
request[0][i] = objectName;
request[1][i++] = url;
}

public function startPreload(completeHandler:Function):void
{
this.contentLoaderInfo.addEventListener(Event.COMP LETE, completeHandler);

for(i=0; i < request[0].length; i++)
{
var requests:URLRequest=new URLRequest(request[1][i]);
this.load(requests);
}
}
}
}

scottc
January 8th, 2009, 05:36 PM
You could try use one of the loader classes... there are 2 listed under network in the link in my sig "useful as3 libs".

snozbunny
January 9th, 2009, 12:10 AM
Good reference. I will deconstruct it. Thanks again for the help.