Currently I have a function (LoadImg) that will load the given file location and return the loader. It’s good practice to also include what amounts to ‘when the image has actually COMPLETED loading’ line in. This is usually done with an event handler. But with such you can only say once the image has loaded run another function. But I need the ‘LoadImg’ function to return the image.
function LoadImg(Img:String):Loader
{
var myLoader:Loader;
myLoader=new Loader();
myLoader.load(new URLRequest(Img));
return myLoader;
}
How can I say only return ‘myLoader’ when it’s completed?
I don’t think its possible to use a synchronous call (function return) with an asynchronous event (loader complete).
Attaching an event listener to the Complete event is the way to go, not sure how that will fit into your code.
Here is a similar question which might be useful: Image size in AS3, the response is useful to your question.