Today I finished my asset loader class, which can load any type of asset. This can be very helpful! Loading external images or swf files became a daily procedure, so why not writing my own asset loader class that is agile and easy to use?

I know! Not really rocket science, but it’s extremely useful! This asset loader class acts more like a helper class, you can write your own custom asset (by extending the asset). What I like very much is the ability to attach a preloader asset to it. When writing your own custom asset, you have access to all loader events so you can write for example a nifty preloader.
It’s not CPU intensive, because the Loader Object (which holds the original image content) will be detroyed after an image is succesfully loaded. You can imagine that you want to load an image of 5mb (with a big ass resolution) and you want to resize it to lets say 400px in width. Normally this give performance issues, because 5mb is still in memory. This asset loader resizes that image to desired width and height and initially deletes the original image from memory, which will improve the swf performance.
Example loading a transparent image:
var asset:Asset = new Asset("images/picture.png"); addChild(asset);
Example loading an external swf and call the method start() in the swf that’s loaded after it’s loaded completely:
var asset:Asset = new Asset("swf/controller.swf"); asset.addEventListener(AssetEvent._EVENT, handleAssetEvents); addChild(_asset); private function handleAssetEvents(event:AssetEvent):void { if (event.subtype != AssetEvent.COMPLETE) return; var asset:SwfAsset = Asset(event.target).content as SwfAsset; var swf:IController = asset.getLoadedAsset() as IController; swf.start(); }
Images can be resized to different types:
- AssetResize.FIT, resize the image to fit given bounderies
- AssetResize.FILL, make sure the given bounderies are filled.
- AssetResize.FILL_MASKED_[TL,TR,CENTER,BL,BR], image will be cropped and masked by the given bounderies
Usage:
var asset:Asset = new Asset("images/picture.png", new AssetImageData(300, 300, AssetAlign.CENTER, AssetResize.FIT)); addChild(asset);
Demo:
Download source files
It’s still work in progress, there may be minor bugs in it. Feel free to give it a try and don’t hesitate to comment me!







1 Comment
This is Really helpfull! Thnx