Some favorite site feeds aggregated locally: iPhone Development RSS   Adobe Labs RSS   Macrumors RSS

Tuesday, November 27, 2007

AS3 Class: BulkLoader

Tuesday, November 27, 2007   

Saw this on the aggre's this morning, and I want to post another link to it, Arthur Debert has released a really cool AS3 class he calls BulkLoader. It's implementation is pretty nice, some sample usage code:
import BulkLoader;
var loader:BulkLoader = new BulkLoader("main");
loader.add("bg.jpg");
loader.add("config.xml");
loader.add("soundtrack.mp3");
loader.add("intro.flv");
loader.addEventListener(BulkLoader.PROGRESS, onProgress);
loader.addEventListener(BulkLoader.COMPLETE, onComplete);
loader.start();

function onProgress(evt : BulkProgressEvent):void
{
trace(evt.percentLoaded);
}

function onComplete(evt:Event):void
{
var bgBitmap = loader.getBitmap("bg.jpg");
addChild(bgBitmap);
var video : Video = new Video();
video.attachNetStream(loader.getNetStream("intro.flv"));
parseConfig(loader.getXML("config.xml"));
}
Without looking at the support class(es) yet, I assume that it goes through in the order which you added the assets. And you can use keys on retrieval (very nice). Well done, this looks like a really nice direction to take for loading in lots of assets (ie. sites and also larger applications).
 
 Return to the main page
Comments:

There are currently 7 Comments:

Anonymous Zeh said...
“It does go through the order you added, but it also allows setting the priority of the loading queue if something needs a higher priority.”
 
Blogger e.dolecki said...
November 27, 2007 9:20 AM
“Well done zeh, you've added a lot of flexibility into this.”
 
Anonymous Zeh said...
November 27, 2007 9:58 AM
“Ah, don't get me wrong - I'll be using it on my next AS3 projects, but it's all Arthur's work; I had no part in this except for a few suggestions and questions. The thing was already pretty consistent before I even knew about it.”
 
Blogger arthur_debert said...
November 27, 2007 8:27 PM
“Hi Eric.

Yes, items will be loaded in the order they've been added, but you can set a particular priority for it:

loader.add("bg.jpg", {priority:100});
// this will load the bg file before others (priority defaults to 0)

Thanks for taking the time to look at the project, and if I can answer any questions, I'd be glad to.

Cheers
Arthur”
 
Blogger Laurent Kappler said...
December 19, 2007 8:40 PM
“Hi Arthur,

A question knocks my brain since I use your codes (you and Zeh), why do you use object to store properties/parameters instead of function attributes. It seems more flexible but heavier...I have no idea finally, what made your choice ?

Nice design for the get().methods() syntax and the possibility to instanciate a BulkLoader(loading queue) for any page or class in a flash document. If we start a new instance does it stop loading the other instance automatically ?

Certainly the most used class in my next projects, with Zeh's Tweener class. GG!”
 
Blogger Laurent Kappler said...
December 19, 2007 9:30 PM
“...hmkey...now I see the possible optionssss with the object parameters and my question about flexibility/heavyness looks as erilevant as it would be such a pain to handle many options as arguments of a method. So using an object for props is a design kicks-ass trick when considering flexibility.”
 
Blogger arthur_debert said...
December 20, 2007 6:44 AM
“@Laurent:

I can't really speak for Zeh, but I can speak for my self ;-)

Passing eight options as paremeters is unwieldy. Sometimes you only want to specify the last one, and then you have to pass a lot of undefined / null values. Besides, remembering the order is error prone too.

For me, this is an ugly hack, needed because we don't have a feature like python's named parameters (which I really, really miss).

The other option would be to instantiate an object, keep setting properties on it and than pass that. This is more structured but seems a bit heavy for a few cases, besides making users import and learn more that one class of documentation.

Passing a lot of optional parameters by means of a hash feels nice. Ruby on Rails use it extensively, for example.

Cheers
Arthur”
 
 Leave a comment