Judging from your code, it looks like iLoader
is a variable scoped to the function loadImg
. You can't access it by that name outside of loadImg.
One workaround is to put your declaration of iLoader in a broader scope. In this case, that would be outside of all the functions, as David Mear suggests.
However, you should be able to get around it in a more graceful way. Every event in AS3 has a target property. In this case, the target should be your loader. So inside onLoaderReady
, you should be able to do the following:
this.stage.addChild(e.target);
There's a chance this may not work - since the loader is no longer in scope, it may be deleted. I believe it will stick around long enough for this line of code to succeed, but don't have any way of testing right now. If you try it and it fails, we'll just go with David's answer and I'll delete mine.