Unloading swf from parent swf
So I loaded a swf into another swf like so
correctURL being my external swf variable
function startLoad(){
var mRequest:URLRequest = new URLRequest(correctURL.toString());
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, o开发者_Go百科nProgressHandler);
mLoader.load(mRequest);
}
function onCompleteHandler(loadEvent:Event) {
var gmc:MovieClip = new MovieClip();
gmc.x = 266;
gmc.y = 67;
addChild(gmc);
gmc.addChild(loadEvent.currentTarget.loader);
}
But i'm struggling to unload the damn thing when I want to replace it with another swf.
The code i'm trying is this
function closeAllStreams(e:Event) {
e.currentTarget.loader.unloadAndStop();
gmc = null;
gmc.removeChild(e.currentTarget.loader);
trace("unloaded");
}
mLoader.contentLoaderInfo.addEventListener(Event.UNLOAD, closeAllStreams);
I'm just not having any luck as I can still hear the old sound over the top.
I don't want to access the loaded swf's variables either or i'd just cheat haha.
Thanks
Well, unloadAndStop() will work with only Flash-Player 10 and then you dont need to assign null to loader reference, this method does itself. Your closeAllStreams method will be called after this statement
e.currentTarget.loader.unloadAndStop(); OR e.currentTarget.loader.unload();
so its better not to call it inside the unload Event dispatcher i.e closeAllStreams in your case.
Well this is a problem anyway:
gmc = null;
gmc.removeChild(e.currentTarget.loader);
Do I need to explain why
精彩评论