Skip to main content
April 17, 2008
Question

UNLOADING SWF

  • April 17, 2008
  • 1 reply
  • 310 views
Can anyone offer any advice on how to unload swfs that have been loaded into a host SWF.


For eaxmple i have my main movie and am loading an external swf into it
this works fine however when i try to close it with another button in the main movie,
I get this error message

TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::MovieClip@2cf8101 to flash.display.Loader.
at VirtualSynthPiano_fla::MainTimeline/unloadFunction()

This is my code

//button in the main movie that loads the external swf
keyboardDragMC.btBtnMC.addEventListener(MouseEvent .MOUSE_DOWN, loadPlayer);

function loadPlayer(myevent:MouseEvent):void {
var myrequest:URLRequest=new URLRequest("organBluesPlayer.swf");
var myloader:Loader=new Loader();
myloader.addEventListener("UnloadMe", unloadFunction);
myloader.load(myrequest);
stage.addChild(myloader);
}

//button in main movie that should unload the swf
keyboardDragMC.editBtnMC.addEventListener(MouseEve nt.MOUSE_DOWN, unloadFunction);
function unloadFunction(event:Event):void {

Loader(event.currentTarget).unload();
}


After looking around the net this seems to be quite a common problem. Would much appreciate any advice any one could offer?

thanks

Liam.
This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
April 17, 2008
that event's currentTarget property is keyboardDragMC.editBtnMC which is not your loader and is not any loader and is the reason you're receiving that message.

try applying the unload() method to myloader.