0
votes

I have this piece of code that's suppose to add a swf file (homePage.swf) inside my main file (skeleton.fla).

Code:

var mcHome:MovieClip;

var newPage:Loader = new Loader();
newPage.load(new URLRequest("homePage.swf"));

newPage.contentLoaderInfo.addEventListener(Event.COMPLETE, homeLoaded);      

function homeLoaded(event:Event):void {

    mcHome = MovieClip(newPage.contentLoaderInfo.content);
    newPage.contentLoaderInfo.removeEventListener(Event.COMPLETE, homeLoaded);
    addChild(mcHome);  

}

I keep getting this error:

TypeError: Error #2007: Parameter child must be non-null. at flash.display::DisplayObjectContainer/addChild() at skeleton_fla::MainTimeline/homeLoaded()

I don't know how to solve it, or what to change!

Help please, I'm a bit desperate.

1
Make sure that "homePage.swf" is in the same directory as your skeleton.fla and check the spelling of the swf file name - kare
yes, it is. And the name is the same. - nuriaquero
Try addChild(newPage);. eg adding the loader instead of the content of the loader. You wouldn't be getting the complete event if the swf didn't exist. Most likely it's a security sandbox issue. - BadFeelingAboutThis
Now I've got this error: TypeError: Error #1009: Cannot access a property or method of a null object reference. at skeleton_fla::MainTimeline/homeLoaded() - nuriaquero
What does your homeLoaded function look like now? If you're not doing anything else, you can just use three lines of code: var newPage:Loader..... - newPage.load(new URLRequest.....); - addChild(newPage); - then forget the home loaded function and complete listener all together. - BadFeelingAboutThis

1 Answers

0
votes

Is better to add to the displayList the Loader object instead its contentLoaderInfo.content. The Loader is a DisplayObject by itself. There is not need to access to the MovieClip inside of the Loader object although it is possible in the most of environments.

If you try to load an SWF that resides in other domain, you could add the Loader object to the displayList but you can't access to the content property if you don't create a crossdomain.xml file.

var newPage:Loader = new Loader();
newPage.load(new URLRequest("homePage.swf"));

newPage.contentLoaderInfo.addEventListener(Event.COMPLETE, homeLoaded);      

function homeLoaded(event:Event):void {

    newPage.contentLoaderInfo.removeEventListener(Event.COMPLETE, homeLoaded);

    addChild(newPage);  

}

Here you have an example.