Tuesday, November 27, 2007
import BulkLoader;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).
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"));
}
7 Comments:
-
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.”
-
Zeh said...
-
“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.”
-
arthur_debert said...
-
“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” -
Laurent Kappler said...
-
“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!” -
Laurent Kappler said...
-
“...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.”
-
arthur_debert said...
-
“@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”









