Unload external content - Null object error
Hi Ladies and Gents;
I'm new around here, so please bear with me. I know this is a commonly-experienced problem, and I hate to post ANOTHER topic about it, but after three days of reading over dozens of topics and trying to correct this on my own, I'm at a loss. I know I'm doing something wrong, but I don't understand AS3 well enough yet to know exactly what.
I have a parent swf and a child swf. I click a button on the parent stage to open the child swf. I've been trying to make a "return to main" type of button that can be clicked to unload the child swf and bring me back to the parent swf.
Here is the code for the parent:
var myLoader:Loader=new Loader(); qual_btn.addEventListener(MouseEvent.CLICK, qualifications); function qualifications(myevent:MouseEvent):void { var myURL:URLRequest = new URLRequest("qualifications.swf"); myLoader.load(myURL); addChild(myLoader); myLoader.content.addEventListener('killMe', killLoadedClip); } function killLoadedClip(event:Event):void { event.target.removeEventListener('killMe', killLoadedClip); stage.removeChild(myLoader); myLoader.unload(); }
And here is what I have for the child:
back_btn.addEventListener(MouseEvent.CLICK, dispatchEvent); dispatchEvent(new Event("killMe", true));
What's been happening is that I'm getting a null object reference:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Application_workingcopy_fla::MainTimeline/qualifications()
I know the issue is with line 8 of the parent AS:
myLoader.content.addEventListener('killMe', killLoadedClip);
But I don't understand what's wrong with it, or why it's giving me a null object reference.
Please, any advice you can offer would be very, very welcome. I've been at this for three days, but I can't fix it when I don't quite understand what 'it' is that needs fixing.
Thank you.
-Batty