pureMVC assetLoader utility (1)

Yes, another asset loader utility, they seem to be the in thing at the moment, but none of the ones I’ve used are me. They are far too feature rich for my needs, clutter up the global namespace, and since I use pureMVC a lot, I may as have an asset loader utility that actualy is implimented in it.

This is the first version… a very early one, so much that I haven’t even writen any documentation for it. I just need to get it out there, and if not now, when?

At the moment it only loads non-streaming assets (ie those that are only available after Event.COMPLETE), and my aim, apart from those listed below, is to add features only when neccessary.

1) write some documentation
2) impliment streaming file types (flvs, mpgs and zips)
3) refactor for use without pureMVC (maybe)

[kml_flashembed movie=”http://www.revisual.co.uk/swf/assetloader.swf” height=”500″ width=”470″ /]

To create and register the AssetLoaderProxy:

var assetLoader:AssetLoaderProxy;
assetLoader = new AssetLoaderProxy();

To retrieve an asset:

var asset:IAssetContainer;
asset = assetLoader.getAsset("filePath/myFile.jpg")

The AssetLoaderProxy will return an IAssetContainer which either contains the asset (if it has been previously loaded and stored) or the information that will enable the loading of the asset. So the first thing to do is to check to see its loaded state:

    trace("this asset has already been loaded")
    trace("this asset has not been loaded yet")

If the asset has already been loaded, it can be accessed either via the getAsset():Object method, or using any of the pre-typed getters.

To load an asset:
If the asset has not already been loaded, listeners, loader contexts and other properties can be added to the IAssetContainer, before it is passed back to the AssetLoaderProxy load que.

asset.addEventListener(Event.COMPLETE, completeHandler);
asset.addEventListener(ProgressEvent.PROGRESS, progressHandler);
asset.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);

Note on Typing:
The loaded assets will be typed as its loader types it. For example, an XML file is loaded with a URLLoader and is therefore a String. At no point will this String be parsed as an XML within the AssetLoader utility until you call the getAsXML() method from the IAssetsContainer. The string will then be parsed and stored as an XML. If you want to keep it as a String, always call the getAsset() and type it, or call getAsString(). This is a good thing, as it gives you more control over it (ie changing whitespace settings before parsing).
The type of asset can be ascertained through its fileType property, which is basically just the file extension.

The AssetLoaderProxy also sends pureMVC Notifications. You can use its enumerated static constants to register commands that will respond to these.


The AssetLoaderProxy instance will be passed as the body of the Notification, so any information required can be taken from its public properties.

And finally:
So, that gives a very quick over view. The next thing I’ve got to do is commenting documentation, and perhaps some UML diagrams.

I Have created a google code account, for this and other pureMVC utilities. I intend to get a fully featued download out at the end of July.