Copy link to clipboard
Copied
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();
}
Copy link to clipboard
Copied
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.
If I understand you right and the Navigaton.swf is a child of your Main Movie, you can trigger any if its functions by using either
this.parent.Click_To_Close
or dispatching a custom Event (for which you have to listen in your main movie)
that triggers the closing
Copy link to clipboard
Copied
thank you
i have tried to use this.parent.Click_To_Close but it gives compilation error
i checked the tutorial about custom events i think its little complex for me now to understand the typeriter app.
also i cheked the similer thread and tried to test that code myself..i found that the last block of main movie does not works and does not unload the loader2. however all the trace are showing in the output windows that i added to check the code but last trace from the main movie is not showig...
trace("child removed from Main Movie")
so if this can work somehow i will use this method of event dispatch in my application that i am working...
Thank you
-----main movie ---------
var loader1:Loader = new Loader();
var loader2:Loader = new Loader();
loader1.contentLoaderInfo.addEventListener(Event.COMPLETE, assignMovie1Listener);
loader1.load(new URLRequest("movie_1.swf"));
loader2.load(new URLRequest("movie_2.swf"));
addChild(loader1);
addChild(loader2);
function assignMovie1Listener(evt:Event):void {
MovieClip(evt.currentTarget.content).addEventListener("eventTriggered", removeLoader2);
trace("listner is listning..")
}
function removeLoader2(evt:Event):void {
loader2.unloadAndStop();
removeChild(loader2);
loader2 = null;
trace("child removed from Main Movie")
}
//------------- movie_1.swf code:
removeMovie2_btn.addEventListener(MouseEvent.CLICK , removeMovie2);
function removeMovie2(event:MouseEvent):void
{
dispatchEvent(new Event("eventTriggered"));
trace("event triggered form Child Movie-1");
}
as u can see when i click close button its triggering the trace from movie-1 but its not unloadign the movie2
Copy link to clipboard
Copied
Strange,
try to get rid of the line
loader2.unloadAndStop();
and see how that goes
Find more inspiration, events, and resources on the new Adobe Community
Explore Now