Simple LoaderMax Example
I stumbled a bit getting GreenSock’s LoaderMax bulk loading utility running from an XML doc, but after looking through multiple examples in the documentation I have it working. Here’s the deal:
Ready: The XML
The structures doesn’t matter much overall until you define the loader elements. You can add anything LoaderMax supports. I’m just loading some images.
<?xml version="1.0" encoding="UTF-8"?> <manifest> <images> <ImageLoader name="largeMap" url="assets/images/bg_largeMap.png" estimatedBytes="3300" load="true" /> <ImageLoader name="shortMap" url="assets/images/bg_shortMap.png" estimatedBytes="6600" load="true" /> </images> </manifest>
Set: Loading
First you need to activate the loaders you’re going to use. Then fire up XMLLoader and load the xml document. XMLLoader will sniff out any known and activated loader and process it according to the rules you define in the xml.
LoaderMax.activate([ImageLoader]); var loader:XMLLoader = new XMLLoader("assets/xml/artworkManifest.xml", {name:"xmlDoc", onComplete:onReady}); loader.load(); private function onReady(e:LoaderEvent) : void { // finish up or whatever }
GO!
You’ll call a static function to retrieve the asset.
// when the asset is needed var staticMap:Sprite = Sprite( LoaderMax.getContent("shortMap") ); addChild(staticMap);
You’ll also want error handling and display progress, etc. Hit the docs for more details about that.
» continue readingCategories: Flash • Permalink


