我已经加载了一个外部swf文件,默认情况下会在加载swf时播放flv文件。现在的问题是如何从内存中删除swf文件。我的代码:
var myLoader:Loader = new Loader();
var url:URLRequest = new URLRequest("ExternalSWF.swf");
myLoader.load(url);
detailMovieClip.movieHolder.addChild(myLoader);
我尝试了很多removeChild,unload和unloadAndStop的组合,但都没有。我认为所有这些都没有正确引用。
更新
我选择了Jegan的答案,但只有当我在一个只有1个numChildren的虚拟项目中进行测试时,它才起作用,在现实世界的代码示例中,numChildren报告22,所以我不确定这是否是一个问题。这是现实世界的代码:
var myImageLoader:Loader;
var myImageRequest:URLRequest;
var theImagePath:String;
//part from xml processor function
theImagePath = "flash/"+myXML..item_video_link[n];
loadTheMovie(theImagePath);
function loadTheMovie(theImagePath):void{
myImageLoader = new Loader();
myImageRequest= new URLRequest(theImagePath);
myImageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,showMeTheVideo);
myImageLoader.load(myImageRequest);
}
function showMeTheVideo(evt:Event):void{
detailsMovieClip_mc.details_video_holder.dynamicVideoHolder.addChild(myImageLoader);
}
stopVideo(sectionname):viod{
if(detailsMovieClip_mc.details_video_holder.dynamicVideoHolder.numChildren !=0){
trace("what is the number of children: "+numChildren);
myImageLoader.unloadAndStop();
detailsMovieClip_mc.details_video_holder.
dynamicVideoHolder.removeChild(myImageLoader);
}
}
答案 0 :(得分:1)
stage.addEventListener(MouseEvent.CLICK, removeSWF);
function removeSWF (e:MouseEvent):void
{
if(detailMovieClip.movieHolder.numChildren !=0){
myLoader.unloadAndStop();
detailMovieClip.movieHolder.removeChild(myLoader);// empty the movieClip memory
}
}
OR
为Loader
个实例命名,然后使用getChildByName
myLoader.name = "myloader";
function removeSWF (e:MouseEvent):void
{
if(detailMovieClip.movieHolder.numChildren !=0){
Loader(detailMovieClip.movieHolder.getChildByName("myloader")).unloadAndStop();
detailMovieClip.movieHolder.removeChild(detailMovieClip.movieHolder.getChildByName("myloader"));// empty the movieClip memory
}
}
答案 1 :(得分:0)
我想这是因为您正在将加载程序添加到场景中。
要么保留此行为,在这种情况下有一个快速修复,使用removeChild()从MovieClip中删除加载器,然后将引用设置为null,或使用delete关键字。
要么你想要正确地执行它,在这种情况下,侦听LOADED事件,将loader.content包含的MovieClip添加到目标MovieClip。然后,当您想要卸载它时,使用removeChild(),然后使用loader.unload()从容器中删除剪辑。