Adding or Removing Event Listeners all at once?
Hello!
I'm trying to do something that I'm not sure if it's possible.
I have to add or remove multiple listeners that will trigger the same three methods (onComplete, onError and showProgress).
I was trying to do something like this:
Start with:
addListeners(bkgLoader); //that runs the following method:
private function addListeners(e:Loader):void {
e.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
e.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError);
e.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, showProgress);
}
The problem is that I just can't reutilize this because onComplete and onError I'm forced to "hardcode" bkgLoader again, for example:
private function onError (e:IOErrorEvent):void {
removeListeners(bkgLoader); //bkgLoader hardcoded here.
trace("IOError occured");
}
Is there anyway to solve this? It seems that after passing through the addListeners method, the loader instance gets lost.
Thanks!