2015-12-30 39 views
0

我有这段代码,这是假设在我的主文件(skeleton.fla)中添加一个swf文件(homePage.swf)。addChild()问题:AS3上的错误2007

代码:

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

我不知道如何解决这个问题,还是要改变什么!

请帮忙,我有点绝望。

+0

请确保“homePage.swf”与您的skeleton.fla位于同一目录中,并检查swf文件名称的拼写 – kare

+0

是的。名字是一样的。 – nuriaquero

+0

尝试'addChild(newPage);'。例如添加加载器而不是加载器的内容。如果swf不存在,你不会得到完整的事件。很可能这是一个安全沙箱问题。 – BadFeelingAboutThis

回答

0

最好添加到displayListLoader对象,而不是它的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你有一个例子。

+0

考虑通过解释为什么加载器需要添加而不是内容来使你的答案更有用。 – BadFeelingAboutThis

+0

好的@BadFeeling关于这个,我会尽量训练我的英语不好;) – ElChiniNet

+0

这实际上并不是真的,甚至不是一个有效的答案,尽管它已被标记为接受。关于为什么加载器比加载内容更好添加没有任何理由。 – BotMaster