简体   繁体   中英

remove external swf file as3

I have loaded an external swf file which plays a flv file by default as swf is loaded. Now the problem is how do i remove the swf file from memory. 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. 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. 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

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.

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.

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. Then, when you want to unload it, remove the clip from the container using removeChild(), then loader.unload().

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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