unload external SWF using event dispatch
Hi i am working on a flash website where i have a main movie named as Navigation where i have all the navigation buttons and drop menus. i am using switch case method to load multiples external SWFs. so as user clicks on any of the navigation button...it loads the external SWF
now i have a close_btn in the loaded SWF and i simply want the unload the external SWF when user clicks on the close_btn.
I come to know that i can do this by event dispach but i am not sure what code to put in external swf so when close_btn is clicked it can access the unloader function in main movie and unload the External SWF.
Could you Please help, Thank you !
this is my code
//--------main swf---------------------
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.*;
import flash.net.URLRequest;
home_btn.addEventListener(MouseEvent.CLICK,Click_To_Close);
ourstory_btn.addEventListener(MouseEvent.CLICK, clickHandler);
facility_btn.addEventListener(MouseEvent.CLICK, clickHandler);
customers_btn.addEventListener(MouseEvent.CLICK, clickHandler);
sustainability_btn.addEventListener(MouseEvent.CLICK, clickHandler);
contactus_btn.addEventListener(MouseEvent.CLICK, clickHandler);
// Dropdown Menu1 Buttons
menu1.menu_mc1.organicinitiative_btn.addEventListener(MouseEvent .CLICK, clickHandler);
menu1.menu_mc1.myhope_btn.addEventListener(MouseEvent.CLICK, clickHandler);
menu1.menu_mc1.target2015_btn.addEventListener(MouseEvent.CLICK, clickHandler);
// Dropdown Menu2 Buttons
menu2.menu_mc2.mens_btn.addEventListener(MouseEvent.CLICK, clickHandler);
menu2.menu_mc2.womans_btn.addEventListener(MouseEvent.CLICK, clickHandler);
menu2.menu_mc2.teans_btn.addEventListener(MouseEvent.CLICK, clickHandler);
menu2.menu_mc2.babies_btn.addEventListener(MouseEvent.CLICK, clickHandler);
var loader:Loader = new Loader();
addChildAt(loader,0);
function clickHandler(e:Event):void{
switch(e.target.name){
case "ourstory_btn": loader.load(new URLRequest("ourstory.swf")); break;
case "facility_btn": loader.load(new URLRequest("facility.swf")); break;
case "customers_btn": loader.load(new URLRequest("customers.swf")); break;
case "sustainability_btn": loader.load(new URLRequest("sustainability.swf")); break;
case "contactus_btn": loader.load(new URLRequest("contactus.swf")); break;
case "organicinitiative_btn": loader.load(new URLRequest("organicinitiative.swf")); break;
case "myhope_btn": loader.load(new URLRequest("myhope.swf")); break;
case "target2015_btn": loader.load(new URLRequest("target2015.swf")); break;
case "mens_btn": loader.load(new URLRequest("mens.swf")); break;
case "womans_btn": loader.load(new URLRequest("womans.swf")); break;
case "teans_btn": loader.load(new URLRequest("teens.swf")); break;
case "babies_btn": loader.load(new URLRequest("babies.swf")); break;
}
}
//-----------my unloader function in main swf --------------------
function Click_To_Close(event:MouseEvent):void
{
if(loader != null) {
loader.unloadAndStop();
}
