Actionscript 3 卸载加载了Loader::load()的SWF
我正在使用Actionscript 3 卸载加载了Loader::load()的SWF,actionscript-3,flash,loader,Actionscript 3,Flash,Loader,我正在使用Loader::load()成功地将swf加载到我的主swf中,然后将它们作为精灵的子级添加。当发生其他事件时,我希望根据需要移除SWF。我查看了unload()和removeChildAt(),但没有成功 我只添加了addChild()调用,试图锁定加载的实例,以便将其删除。没有addChild(),加载工作正常 我还尝试发布到player v.10并使用myLoader.unloadAndStop();但这也没有效果, 下面的演示代码显示了我的问题。我看到添加了一个孩子,删除了一个
Loader::load()
成功地将swf加载到我的主swf中,然后将它们作为精灵的子级添加。当发生其他事件时,我希望根据需要移除SWF。我查看了unload()
和removeChildAt()
,但没有成功
我只添加了addChild()
调用,试图锁定加载的实例,以便将其删除。没有addChild(),加载工作正常代码>
我还尝试发布到player v.10并使用myLoader.unloadAndStop()
;但这也没有效果,
下面的演示代码显示了我的问题。我看到添加了一个孩子,删除了一个,但intro.swf仍然在玩
import flash.display.Loader;
import flash.display.Sprite;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
var myLoader:Loader = new Loader();
var holderMC:Sprite = new Sprite();
var myRequest:URLRequest = new URLRequest('intro.swf');
myLoader.load(myRequest);
holderMC.addChild(myLoader);
trace("initial:"+holderMC.numChildren); // traces initial:1
while(holderMC.numChildren > 0) {
holderMC.removeChildAt(0);
trace("now there are:"+holderMC.numChildren); // traces now there are :0
}
myLoader.unload();
//编辑-还尝试了:
myLoader.unloadAndStop();
myLoader = null;
有什么想法吗?你肯定还有别的想法。首先,你是如何看待“intro.swf”的?您正在创建holderMC,并将加载的swf作为子项添加,但何时将holderMC添加到显示列表
从视图中删除电影的正确方法是:
holderMC.removeChild(myLoader);
为了让holderMC的内容标记为垃圾收集,需要将其设置为null。所以
holderMC.removeChild(myLoader);
myLoader.unload(); // this will set the content (the movie itself) to null.
myLoader = null; // npw the loader can be garbage collected too
如果您正在执行removeChild,但它仍在显示,则需要发布更多代码以显示问题的真正所在。谢谢您的回答!我认为问题在于我正在将一个旧的AS2文件转换为AS3,当我开始使用一个新文件并使用您的建议时,问题就解决了。谢谢