a good idea would be, to create external SWFs, that embed images, that are likely to be used together, if that is possible at all ... something like projectiles.swf, obstacles.swf, enemies.swf, misc.swf .... i don't know ... something that makes sense ... maybe divide assets by levels, or something ... take a simple interface, that allows you to extract assets from an swf ... for example, let there always be a class Assets
, with a static method getAll
, which returns an Object, mapping string identifiers to corresponding classes, so you will get something like:
function onComplete(e:Event) {//this is the handler for the loading operation
var map:Object = (e.target as LoaderInfo).applicationDomain.getDefinition("Assets").getAll();//should return something like {"bullet1":Bullet1,"bullet2":Bullet2,...}
//do whatever you need to do with it
}
advantages:
- images get compressed one against another, so overall filesize will be decreased ...
- you drastically reduce request count on your server ...
- you don't wind up with n-hundred files, following some name/path convention, or even not (also, you need to have a file index somewhere, to know, which files exist and which don't) ...
- you can easily reskin your app by loading a different swf, instead of loading n-hundred images seperately ...
- the ultimate advantage of this approach is, that you will have classes, that you can simply instantiate, instead of loading images over and over again ... the first operation is synchronous, the latter is not ... if you really need to do that, consider loading the image in binary form into a
ByteArray
using URLLoader
, and then getting it on stage with Loader::loadBytes
...
you may want to generate the swfs on serverside using swfmill, to automate the process ...