AS3 BulkLoader Useful Flash Asset Loading Kit by Arthur Debert

Found via Zeh, this great bulk loading kit for AS3 from Arthur Debert.

AS3 Loaders are very useful, but when you have large projects there is always a pause and focus on loading scenarios and architecture needed for your loading scenarios, sometimes this can literally eat days and entirely change performance with wrong moves. BulkLoader is a well written kit from Authur Debert that makes loading scenarios or using BulkLoader as a base to your loading situations a great pluggable piece of code that has many excellent features.

Some of the calls like BulkLoader.getLoader(“main-site”).getContent(“bg”), are also very similar to Silverlight’s downloader object that can be queued like this. All in all a kit that is very useful that I have already put to work and will help teams standardize on bulk loading for those killer flash apps.

Creating a BulkLoader instance:

// creates a BulkLoader instance with a name of "main-site", that can be used to retrieve items without having a reference to this instance

var loader : BulkLoader = new BulkLoader("main-site");

Add urls to load:

// simplest case:loader

// use an "id" so the item can be retrieved later without a reference to the urlloader
.add("background.jpg", {id:"bg"});

// since the url by itself can't tell us what the filetype is, use the type property to let BulkLoader know what to do:loader
.add("/some-web-services?size=Large", {type:"image"});

// add an item that should be loaded first (higher priority):loader
.add("/data/config.xml", {priority:20});

// add a max trie number (defaults to 3)loader
.add("/unreliable-web-services.xml", {maxTries:6});

// you can also use a URLRequest object , this will load from a POST request

var postRequest : URLRequest = new URLRequest("/save-prefs.php");postRequest
.method = "POST";

var postData : URLVariables = new URLVariables(myPostDataObject );postRequest
.data = postData;loader
.add(postRequest, {"id":"settings"});

// of course, all options can be combined:loader
.add("the-sound-webservices?name=maintrack", {"id":"soundtrack", type:"sound", maxTries:1, priority:100});

Listening for events:

// attaching events to all items:

// this will fire once all items have been loadedloader
.addEventListener(BulkLoader.COMPLETE, onAllLoaded);

// this will fire on progress for any item

// the event , BulkProgress is a subclass of ProgressEvent (with extra information)loader
.addEventListener(BulkLoader.PROGRESS, onAllProgress);

// this will fire if any item fails to load:

// the event is BulkErrorEvent and holds an array (errors) with all failed LoadingItem instancesloader
.addEventListener(BulkLoader.ERROR, onAllError);

// you can also listen to events in individual items               

// this will fire as soon as the item registred with the id of "bg" is done loading (even if there are other items to load)loader

// this will only trigged if the config.xml loading fails:loader
.get("data/config.xml").addEventListener(BulkLoader.ERROR, onXMLFailed)

Starting the loading operation:

BulkLoader will only begin loading once you call the start method:


Retrieving content:

You can retrieve an untyped object and cast it your self:

var theBgBitmap : Bitmap = loader.getContent("bg") as Bitmap;

// you don't need to keep a reference to the loader intance, you can get it by name:

var theBgBitmap : Bitmap = BulkLoader.getLoader("main-site").getContent("bg") as Bitmap;

// you can also use the conviniece methods to get a typed object:

var theBgBitmap : Bitmap = loader.getBitmap("bg");

// grab a BitmapData directly:

var theBgBitmap : Bitmap = loader.getBitmapData("bg");

Other convenience functions: getXML, getText, getNetStream, getSound, getMovieClip, getNetStreamMetaData.

You can retrieve an item using it’s id, it’s url as a String or as the URLRequest object (if the item was created with an URLRequest).

Arthur also has experience on Tweener so making simplified calls and minimalist code to make a library successful is very clear in the notes/goals on the project and the resulting code:

BulkLoader is a minimal library written in Actionscript 3 (AS3) that aims to make loading and managing complex loading requirements easier and faster. BulkLoader takes a more dynamic, less architecture heavy aproach. Few imports and making heavy use of AS3’s dynamic capabilities, BulkLoader has a one-liner feel that doesn’t get your way.

BulkLoader tries to hide the complexity of loading many data types in AS3, providing a unified interface for loading, accessing and events notification for different types of content.

This library is licensed under an open source MIT license.


  • Connection pooling.
  • Unified interface for different loading types.
  • Unified progress notification.
  • Events for individual items and as groups.
  • Priority
  • Stop and resuming individually as well as in bulk.
  • Cache managing.
  • Statistics about loading (latency, speed, average speed).
  • Multiple kinds on progress indication: ratio (items loaded / items to load), bytes , and weighted percentage.
  • Multiple number of retries.
  • Configurable logging.

Design goals:

  • Minimal imports.
  • Few method to learn.
  • Dynamic nature: items can be added by specifying a url as a String or a URLRequest .
  • Items can be assigned an identifier key to be used on retrieval.
  • Only one class to learn / use.

BulkLoader tries to gracefully handle progress notification in these use cases:

  • Few connections to open: bytes total can be used instantly.
  • Many connections opened: progress by ratio
  • Many connections opened for data of widely varying sizes: progress by weight.

Check out and download AS3 BulkLoader!

This is quite a contribution to the flash community and is a perfect candidate for the base of your loading assets projects and scenarios. Thanks Arthur!

10 Responses to “AS3 BulkLoader Useful Flash Asset Loading Kit by Arthur Debert”

  1. AS3 Bulk Loader Library by Arthur Debert at .swfgeek Says:

    […] This morning reading my feeds I found a great Library for AS3 posted by Zeh, the Bulk Loader kit nicely written by Authur Debert it’s meat to make complex loading easy freeing you from the Loading and letting you concentrate on other parts of your project. The project is released under the MIT Licence Ryan Christensen posted an example of how to use it at his blog [draw.logic] […]

  2. Arthur Debert Says:

    Hi Ryan!

    Thanks a lot for the kind words and the great review.

    The project is in it’s infancy, and there’s a lot be tweaked and learned. I hope the actionscript developers community find it useful! Any feedback, complaints and feature request are very welcome.

    Thank **you**

  3. Stan Reshetnic Says:

    Hi, nice util. Similar but not so featured I have done for one project. A point that I achieved to simplify API is don’t use event dispatcher. Because each added listener need to remove lately. So instead of using addEventListener need just put function link to util.
    For example:
    util.load([“test.swf”, test.jpg, test.mp3], onFinish);
    When load finished then onFinish link called and removed from util. If Client need to remove handler before load finished, then he calls:
    util.removeHandler([“test.jpg”, test.swf”, test.mp3], onFinish);
    Set of content urls is used as unique id and help to determine which handler to remove. Maybe that can help you simplify class usage. As for me listening for all possible events is a pain. Let client code only know when loading finished, and then check with util.isSuccess(“test.swf”) or something similar. It is kind of usability for client code .

    But feature list of your util is awesome…

  4. drawk Says:

    Hey Aurthur, yeh threw it into a project I was mulling over writing another loading scenario. This is a great start for anyone thanks for adding it to the wild.

    Hey Stan, yes at a small scale events can seem troublesome, but AS3 has a great clear event model and usage for scalability and performance always uses messaging or events. Flags are great for smaller scale but as you scale massively they become a trouble point. Events are much more component independent. Think of the difference as flags are a TCP/IP connection with validation, where events are a UDP like braodcast that allow more async and parallel handling.

    But all approaches work to this, I really dig the event model in AS3 and ES4 as it is greatly simplified and can really make for really independent kits and typed events etc. It all goes back to your usage and your needs, I would say most open source AS3 rides on teh event model pattern that is developing which makes it easy to have a low barrier of entry. The best software developers don’t write for complexity, their simple components handle the complexity and when kits are in the wild they need to be simple, performing and scalable.

    The AS3 community is surely a very feature rich and full or great tools and competition in only a year really (well if you weren’t playing with Flash 8.5 during the transition). Sure is some cool stuff being built and going on.

  5. surrealanimation Says:

    does anyone happen to have BulkLoader Source files that include either a progressbar and or a textField that displays load progress. When trying to use bytesLoaded I get illegible characters, but the output traces correctly. Whe trying to use the _bytesTotal it works but for some reason the first Numeral is missing (ie if the value is 12345 textfield reads 2345, but again output is traced correctly. Revised function below:

    public function onAllItemsProgress(evt : BulkProgressEvent) : void{
    trace(“byteseTotal = ” + evt.bytesTotal);
    trace(“byteseLoaded = ” + evt.bytesLoaded);

    _bytesLoaded = evt.bytesLoaded;
    _bytesTotal = evt.bytesTotal;
    lt = new TextField();
    lt.x = 100;
    lt.y = 300;
    lt.autoSize = TextFieldAutoSize.LEFT;

    ltFormat = new TextFormat();
    ltFormat.font = “Arial”;
    ltFormat.size = 50;

    _loaded = String(_bytesLoaded);
    _total = String(_bytesTotal);

    _number = 333444555666777;
    _string = String(_number);

    lt.text = _total;

    trace(“lt.text = ” + lt.text);
    trace(“typeof _bytesLoaded = ” + typeof _bytesLoaded);
    trace(“typeof _loaded = ” + typeof _loaded);
    trace(“ltFormat.size = ” + ltFormat.size);

  6. arun kumar Says:

    There is some problem in the web designing,some of the information not being displayed properly :
    simply add this code to your Cascading Style Sheet :
    to the :
    wrap: soft/hard;

    then u can get the difference

    Any Way thanks for providing such a good material.

  7. Anthony Says:

    hello guys,
    while trying to load a swf version 2.0 i get the following error
    **TypeError: Error #2007: Parameter child must be non-null.
    at flash.display::DisplayObjectContainer/addChild()…………..**
    bulkloader can’t load movie clips version 2.0??
    another question can bulkloader load dynamic swf files??
    please i need your help:)
    Anthony youssef

  8. John Says:

    Having major problem with BulkLoader.

    I run it locally…it works perfectly.

    I listen for the COMPLETE event.

    When I put it up on the server:
    – the COMPLETE event fires
    – any content I go to retreive is null!!
    – even when, the event itemsLoaded == itemsTotal, and percentLoaded == 1.

    What could I be doing wrong here? The getContent is only null when I run it live.

    Any help is welcomed greatly.


  9. drawk Says:

    What type of file are you loading? If it is one that is not supported by the server (as dae is commonly not) it can hang on a mime-type.

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

%d bloggers like this: