addChild() 问题:AS3 上的错误 2007

addChild() issue: error 2007 on AS3

我有这段代码应该在我的主文件 (skeleton.fla) 中添加一个 swf 文件 (homePage.swf)。

代码:

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);  

}

我不断收到此错误:

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

不知道怎么解决,不知道改什么!

求助,我有点绝望

最好将 displayList 添加到 Loader 对象而不是 contentLoaderInfo.contentLoader 本身就是一个 DisplayObject。不需要访问 Loader 对象内部的 MovieClip 尽管在大多数环境中是可能的。

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你有一个例子。