开发者

array of loaders?

How does one create an array of loaders?

The bigger picture:

I have written a mapping program in flex. I want to change my mapping program so that all I need to do is drop in a new xml file instead of going into my flex file and adding the exact number of item loaders I need. So I guess I'm looking for an array of loaders that can load the image files that are within my XML file.

xml file example:

<locations>
      <location>
        <name>Big Star</name>
        <street>123 Some St.</street>
        <city>City</city>
        <state>XX</state>
        <zip>555555<开发者_JS百科/zip>
        <lat>12.34567</lat>
        <long>-67.54321</long>
        <iconFile>bigStar_icon.gif</iconFile>
        <imageFile>bigStar_img.swf</imageFile>
        <motion>no</motion>
        <featured>yes</featured>
        <category>Grocery</category>
      </location>
</locations>

this xml can sometimes have 2000 locations.


Yeah, that's a pretty bad question. Literally (if facetiously):

var loaders:Array = [new Loader(), new Loader()];

Trying to read into what you asked, it sounds like you are trying to load up a whole bunch of stuff and handle them all loading together somehow... and if you have to ask, you're going to struggle.

You could try using the Bulk Loader library though, which does this for you reasonably well. There are probably others.


Not a direct answer to the question since it's a bit vague + @alecmce already gave an answer (I would go for a loader queue such as BulkLoader in this situation as well).

However, since I noticed a similar question some time ago I just wanted to point out that instantiating all the loaders at once just feels a bit wrong.

Wouldn't it be a bit appropriate to just store the urls and handle process them one by one ?

Basic example : (beware I typed it in without testing...)

// So here's the point: only Strings are stored ... 
var urls:Array = new Array('image1.jpg','image2.jpg',image3.jpg);  

loadNext();

function loadNext()
{
    if(urls.length() == 0)
        return;

     load(urls.shift())
}

function load(url:String):void
{
    // The loader is created lazily just before before we need it
    var loader:Loader = new Loader(new URLRequest(url));
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded)
    loader.load(url);

}

function onLoaded(e:Event):void
{
     event.target.removeEventListener(Event.COMPLETE, onLoaded);
     addChild(event.target.content); // ... or whatever has to happen here.
     loadNext();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜