简体   繁体   English

删除外部SWF文件as3

[英]remove external swf file as3

I have loaded an external swf file which plays a flv file by default as swf is loaded. 我已经加载了一个外部swf文件,默认情况下会在加载swf时播放flv文件。 Now the problem is how do i remove the swf file from memory. 现在的问题是如何从内存中删除SWF文件。 my code : 我的代码:

var myLoader:Loader = new Loader();                     
var url:URLRequest = new URLRequest("ExternalSWF.swf");  
myLoader.load(url);                                     
detailMovieClip.movieHolder.addChild(myLoader);

I have tried many combinations of removeChild, unload and unloadAndStop but none works. 我尝试了removeChild,unload和unloadAndStop的多种组合,但均无效果。 I figure its all about not referencing correctly. 我认为所有有关不正确引用。

Update: 更新:

I went with the answer from Jegan, but it only work when i am testing in a dummy project which has only 1 numChildren, howver in real world code example numChildren reported 22 so i am not sure if that would be an issue. 我从Jegan那里得到了答案,但是只有当我在一个只有1 numChildren的虚拟项目中进行测试时,它才起作用,但是在实际代码示例中numChildren报告了22,所以我不确定这是否是一个问题。 here is the real world code: 这是真实的代码:

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


}
}
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 Name your Loader instance and then search by using getChildByName 或命名您的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
        }
    }

I guess this is because you are adding the loader to the scene itsef. 我猜这是因为您正在将加载程序添加到场景itef。

Either you want to keep this behavior, in this case there is a quick fix, remove the loader from the MovieClip by using removeChild(), then set the reference to null, or use the delete keyword. 您想要保持这种行为,在这种情况下,有个快速解决方法,可以使用removeChild()从MovieClip中删除加载程序,然后将引用设置为null,或者使用delete关键字。

Either you want to do it properly, in this case, listen for the LOADED event, adds the MovieClip contained by the loader.content to the target MovieClip. 您要么要正确执行操作,在这种情况下,请侦听LOADED事件,将loader.content包含的MovieClip添加到目标MovieClip。 Then, when you want to unload it, remove the clip from the container using removeChild(), then loader.unload(). 然后,当您要卸载它时,请使用removeChild()然后是loader.unload()从容器中删除剪辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM