Loading with BulkLoader

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.

Advertisements

9 comments so far

  1. Arthur Debert on

    Hi Greg.

    Thanks for the kind words. Yup, that is exactly BulkLoader’s mission: to take away the pain. I am also baffled that the native API is as inconsistent as it is, which is to say that BulkLoader is only a way to improve on one bad API.

    Cheers
    Arthur

    • bigmac on

      Hey Arthur, it’s an honor to get a comment from the man himself. Agreed on the Flash load architecture – given that it’s a fairly core system within AS3 and it’s fairly clunky and archaic, it leads me to believe that was probably one of the first APIs that they wrote within AS3 and that they were still getting their stride going. At least the load architecture is [slightly] simpler than the sound one…

  2. roy on

    can someone tell me how can i preload the stage with bulkloader…thank you..

    • bigmac on

      Hmmm – that’s not exactly what BulkLoader does. BulkLoader is used to load in large collections of external assets. To preload the stage, you just need a frame-1 timeline script to calculate (loaderInfo.bytesLoaded / loaderInfo.bytesTotal).

  3. kochumvk on

    Thanks for sharing this.

  4. Robert Eriksson on

    Hi!

    I load swfs with bulkloader… these swfs also use bulkloader… I got swfs in swfs..

    then I get:
    [BulkLoader] name:mainpageloader, itemsTotal: 9, itemsLoaded: 1
    ===========
    Error: BulkLoader with name’mainpageloader’ has already been created.
    at br.com.stimuli.loading::BulkLoader$iinit()
    at ips23_interactive_fla::MainTimeline/ips23_interactive_fla::frame1()

    How do I create another mainpage that is not already created?

    kind regards

  5. Robert Eriksson on

    Sorry…

    Solved it.. changed the name… to mainpageloader2… :)
    Thanks for a great tool!!

    Kind regards

    • bigmac on

      LOL – don’t thank me for Bulk Loader, I didn’t create it. I just happened to write a blog post about using it. The real brains is a guy named Arthur Debert.

  6. sawrb on

    Absolutely Brilliant class. I just wrapped up two more apps without the constant fear of all the code coming back to bite me in the ass when its time to write a preloader (yea, I leave it for the end *rolls eyes*). BulkLoader has taken a big chunk of pain away from life. Eternally grateful. However as with any External container-loadedSwf combo, I was skeptical about how stage references were handled. And I just ran into my first one today with BulkLoader. A stage.stageWidth access in the swf being loaded, throws the whole thing off. I’m stuck staring at the infamous Null Object reference error that we As3 devs live with, the whole time. Any pointers here?


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: