I have several PNG files in the project that I want to load manually and avoid preloading, since it slows down the startup. Let’s say, I want to preload the files for the main menu, etc, but then load one image per level before the level starts.
As far as I understand, I can create a separate assets library and add the files that I don’t want to be preloaded there and then preload manually, like it’s described here: XML Format
<library name="myOtherLibrary" preload="false" />
But when I preload it, all the files added to that library will be preloaded. So if I want EACH of the files to be preloaded separately, I’ll have to add a library for each file and then add one file to each library, is it correct?
Is there a better way to achieve my goal: load (PNG) files when I need it without preloading?
var loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onOk);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError);
loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onError);
loader.load('path to your PNG');
function onOk(e:Event):Void {
// load into a bitmap or you can add the loader itself to the display
var bmp:Bitmap = cast this._loader.content;
}
function onError(e:Event):Void {
// handle loading failure
}