I still can't understand how some easy things turns harder in AS3. Here, I would like to load a Bitmap in a function, and, on Complete, return its value to let the app continue. Something like that would be easy to use :
var imageLoader:Bitmap;
for (var i:int=0; i<n.length; i++) {
imageLoader = loadFile(name[i]);
trace(imageLoader); // [object Bitmap]
}
function loadFile(name:String):Bitmap {
imgLoad:ImageLoader = new ImageLoader(url + name)
imgLoad.addEventListener(LoaderEvent.COMPLETE, fileLoaded);
imgLoad.load;
function fileLoaded(ev:LoaderEvent) {
return ev.target.content; // the file now loaded is a bitmap.
}
}
But it doesn't work. The return value must be at the end of loadFile(). I don't really understand what should I do to get my code optimized and working. The first time I tried I used something like a "loopingLoad" method with a "_Count:int" and "_CountEnd" to know when to stop calling loadFile... Well, it was working nice but it was really ugly. So, I would like to know how to simply load several files with a "For".
Thanks for your help.