I've tried many different ways to make this work, but I don't know what's going on. Wish Flash gave more specific error information.
I have a loader SWF that loads and starts another (child) SWF. Everything works perfect until I try adding components to the loader (parent) SWF. After adding components: When the child SWF is loaded and executed, many display objects fail to load and I receive the following error multiple times:
TypeError: Error #2007: Parameter child must be non-null.
at flash.display::DisplayObjectContainer/addChildAt()
at fl.controls::BaseButton/drawBackground()
at fl.controls::LabelButton/draw()
at fl.core::UIComponent/drawNow()
at fl.controls::List/drawList()
at fl.controls::List/draw()
at fl.core::UIComponent/callLaterDispatcher()
I think this button does not get completely destroyed, and interferes with button code in the child swf.
I have the following code:
btnStart.addEventListener(MouseEvent.CLICK, start);
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onGameLoadCompletion);
function onGameLoadCompletion (event:Event):void {
loader.contentLoaderInfo.removeEventListener(Event.INIT, onGameLoadCompletion);
stage.addChild(loader.content);
stage.removeChild(this);
}
function start (event:MouseEvent):void {
btnStart.removeEventListener(MouseEvent.CLICK, start);
loader.load(new URLRequest("childSWF.swf"));
}
There is a button on stage, that was made by dragging the button component into my library, and then onto stage.
I've also tried doing this with only AS code as follows:
import fl.controls.Button;
var btnStart:Button = new Button();
stage.addChild(btnStart);
btnStart.x=670.30;
btnStart.y=486.35;
btnStart.setSize(100,22);
btnStart.label="Continue";
btnStart.visible = true;
btnStart.addEventListener(MouseEvent.CLICK, start);
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onGameLoadCompletion);
function onGameLoadCompletion (event:Event):void {
loader.contentLoaderInfo.removeEventListener(Event.INIT, onGameLoadCompletion);
stage.removeChild(btnStart);
stage.addChild(loader.content);
stage.removeChild(this);
}
function start (event:MouseEvent):void {
btnStart.removeEventListener(MouseEvent.CLICK, start);
loader.load(new URLRequest("childSWF.swf"));
}
Where there is a button in my library but not on stage.
What could be causing this error? I think maybe it is because the child SWF has buttons in it as well. So, how do I properly delete the button in the parent SWF before the child SWF is loaded so that it doesn't affect the child SWF?
This question is from a stand point of figuring out what is different in the child SWF's environment when there used to be a component on stage before it was loaded. Let's pretend I can't modify the child swf. Why does it work perfectly fine before I add components to the parent swf?
Thanks for the help.