During my last jobs I wrote a queue loader class that stores all loaded files for future requests.
DataLib
Overview:
-Static
Since it’s a static class, any loaded file can be used from any parto of the app, even from external SWF files.
-Load queue
Any file must be add to a load queue passing the url and type of file to be loaded. The file can be added at the end of the queue or in a especific position.
DataLib.addItem("file.swf", DataLib.TYPE_SWF); DataLib.addItemAt("file.png", 0, DataLib.TYPE_PNG); DataLib.addItem("file.wav", DataLib.TYPE_BINARY);
Also is possible get the load queue.
var queue:Array = DataLib.queue;
To start loading you must call DataLib.load()
Also it’s possible to pause, resume and close the loading.
DataLib.pause(); DataLib.resume(); DataLib.close();
-Data storage
Every load file is stored for future requisitions. If necessary, files can be deleted freeing memory. Get loaded files using it’s URL.
var image:Bitmap = DataLib.lib[fileURL].data; addChild(image); DataLib.removeItem(fileURL);
-Custom Events
Custom Events cam be added to follow the loading. You can add an event in the class or in a especific item.
*Remember to remove all events from the class to prevent conflicts with other loadings.
DataLib.addItemAt("file.png", 0, DataLib.TYPE_PNG).addEventListener(DataLibEvent.PROGRESS, onItemProgress); DataLib.lib["file.xml"].addEventListener(DataLibEvent.COMPLETE, onItemComplete); DataLib.addEventListener(DataLibEvent.COMPLETE, onComplete); DataLib.load(); function onItemProgress(e:Event):void{ trace(Math.floor(e.bytesLoaded*100/e.bytesTotal)+"%"); } function onItemComplete(e:Event):void{ trace(e.data); } function onComplete(e:Event):void{ addChild(DataLib.lib["file.png"].data); }
-JPG, GIF, PNG, SWF, XML and BINARY
These are the supported files. You can get embed classes in SWF loaded files using the main movie application domain.
DataLib.addItem("asset.swf", DataLib.TYPE_SWF); addChild(DataLib.lib["asset.swf"].data) var EmbedClass:Class = ApplicationDomain.currentDomain.getDefinition("assetEmbedClass") as Class; var instance:* = new EmbedClass();
You can get this and other classes using my google code.
http://andreanaya.googlecode.com/svn/trunk/
Theres also an example of usage of this class.
Thanks and I hope this could be usefull for you guys. Any problem or sugestion please tell me.
Anaya

English
