AS3 / Flash: Introducing the AssetLoader Class
In Actionscript 3, there are many different ways to load external assets from the Internet. Unfortunately, this can become tiresome to find different ways to load each one in it's own individual way. With this problem in mind, I have created the AssetLoader class.
Description
The asset loader class let's you use the same method to load sound, video, pictures, swf's, XML and CSS. The goal for this project is to make loading external assets as simple and clean as possible and give the user all the control they could every possibly need. And even better yet, this class is licensed with the M.I.T. license, so you can do whatever you want with it! Sweet isn't it.
The only official download link:
How Does It Work?
The AssetLoader uses a very simple concept. Items you want to load from the internet have extensions, and with these extensions, there is now a unique way to load them in Flash. So, when you use the AssetLoader, you only need to pass the URL for loading to begin. Of course, you can set up functions to handle events like onComplete, etc. So what does this mean if you are trying to load an xml file that has a php extension? Well you can explicity tell the AssetLoader what type of asset it is. And that's not it, you can also use it as a queue loader! You can set up how many continuous loading you would like to have at any given time and it will handle the rest. Set it to 1, and it is a queue loader. Awesomeness.
What File types are Currently Supported?
Currently, XML, JPG, and Raw Text is supported. I have plans to add support for MP3, WAV, FLV, and other loaders, but because of school and work, I simply don't have the time to make a good quality, official release-able version. You can however EASILY add your own supported types and custom support by creating a new handler in the handlers folder in com.ayanray.loaders using the convention [FileExtension]Loader.as. AssetLoader will also automatically recognize your handler once you have added it there. Please, please contact me if you make your own handler because it is helpful for EVERYONE and that is why I am doing this, to help you.
What Callbacks are Supported?
Currently, the following callbacks are supported generally: onError (general for almost anything that will stop it from loading your file), onComplete, onInit, onUpdate (File Download Progress), onTimeout, and onStart. There might be other ones as well but you will have to check the individual loaders for the advanced features ;).
For all examples, make sure you include the package ;). com.ayanray.loaders.*
Example 1: Loading 1 Asset
new AssetLoader( http://www.ayanray.com/myimage.jpg,{onComplete: handleImageLoadComplete} );Example 2: Loading 2 or more Assets
var obj = new Object();
obj["http://www.ayanray.com/myimage.jpg"] = {onComplete: handleImageLoadComplete};
obj["http://www.ayanray.com/gallerylist.xml"] = {onComplete: handleXMLLoadComplete};
new AssetLoader( obj );
Example 3: Queue Loader
AssetLoaderSettings.MAXLOAD = 1;
var obj = new Object();
obj["http://www.ayanray.com/myimage.jpg"] = {onComplete: handleImageLoadComplete};
obj["http://www.ayanray.com/gallerylist.xml"] = {onComplete: handleXMLLoadComplete};
new AssetLoader( obj );
Example 4: Loading XML with PHP extension
new AssetLoader( http://www.ayanray.com/xmlgenerator.php,{onComplete: handleImageLoadComplete,
filetype: AssetLoaderTypes.XML } );
Questions, Concerns, or Comments?
Please leave a comment if you find this is helpful! Feedback is always appreciated.



Comments