If you’re like me, you find that loading assets into Flash makes you crazy. Face it: remembering several different APIs and then going through the rigors of daisy-chaining load operations together to acquire multiple assets (while doing distributive progress calculations) is a pain in the butt. Oh, and lets not forget error handling! After perfecting your load operation, it’s disheartening to realize that the whole application will hang if your second load fails.
So, wouldn’t it be great if there was a single API that could automatically handle loading all media types, AND manage multiple loads with cumulative progress reporting and a single complete event for the whole operation? I assume that’s what Arthur Debert was thinking when he came up with BulkLoader, which is an AS3 loading framework with all of the aforementioned capabilities, along with several other handy features including connection count settings, prioritization, and file weight calculations. The documentation is also very good! This is an innovation for Flash devs that rivals Galelio’s theories of astronomy; and like The Church’s response Galelio, BulkLoader is probably written off as dark science by Adobe who has never sprung for an all-inclusive loading API like this to include naively within Flash. So, check it out: BulkLoader is open source under the MIT license, and is ultra simple and convenient to use! First, download the library from: http://code.google.com/p/bulk-loader/
Setting up a BulkLoader works like this:
import br.com.stimuli.loading.BulkLoader;
var bulk:BulkLoader = BulkLoader.createUniqueNamedLoader();
bulk.addEventListener(BulkLoader.COMPLETE, this.onLoadComplete);
bulk.addEventListener(BulkLoader.PROGRESS, this.onLoadProgress);
bulk.add("someSWF.swf");
bulk.add("someImage.jpg");
bulk.add("someXML.xml");
bulk.start();
function onLoadProgress(evt:Event):void {
var bulk:BulkLoader = evt.currentTarget as BulkLoader;
// show progress... use bulk.percentComplete
}
function onLoadComplete(evt:Event):void {
// get loader reference and clean up event listeners
var bulk:BulkLoader = evt.currentTarget as BulkLoader;
bulk.removeEventListener(BulkLoader.COMPLETE, this.onLoadComplete);
bulk.removeEventListener(BulkLoader.PROGRESS, this.onLoadProgress);
// acquire loaded assets from BulkLoader
var mc:MovieClip = bulk.getMovieClip("someSWF.swf");
var img:Bitmap = bulk.getBitmap("someImage.jpg");
var xml:Bitmap = bulk.getXML("someXML.jpg");
// purge asset references and clear loader from static registry to make it eligible for garbage collection
bulk.removeAll();
bulk.clear();
}
So, thanks to Arthur for this one! Awesome, convenient, and reliable! I had built a similar load package about a year ago for Lassie’s library manager, but I’ve since replaced the system with BulkLoader since it’s a substantially more robust system with nicer features than in my old light-weight version.
Posted by bigmac
Posted by bigmac