1

Loader::load() 成功地使用将 swfs 加载到我的主 swf 中,然后我将它们添加为 Sprite 的子项。当发生其他事件时,我想根据需要删除 swf。我看过unload()removeChildAt()没有成功。

我只添加了addChild()调用来尝试固定加载的实例,以便我可以删除它。加载工作正常,没有addChild();

我也尝试过发布到播放器 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;

有什么想法吗?

4

1 回答 1

3

你肯定有其他事情发生在这里。首先,您如何看待“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 并且它仍在显示,那么您将需要发布更多代码以显示问题的真正所在。

于 2010-01-23T23:31:46.427 回答