Skip navigation
Currently Being Moderated

Cannot unload external .swf and return to frame 1

Mar 31, 2012 8:48 AM

Tags: #help #flash #swf #actionscript #flash_cs5

I have tried several suggestions on this forum to resolve my issue, but it is obvious to me I am missing something because I am a NOVICE Flash developer. I have everything working in my Flash file EXCEPT I want to use this code to play a .swf file. When the swf file is done playing OR the user clicks the “Return to Main Menu button”, they return to frame 1.

 

stop();

 

Log_In.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF_7);

var fl_Loader_7:Loader;

 

var fl_ToLoad_7:Boolean = true;

function fl_ClickToLoadUnloadSWF_7(event:MouseEvent):void

{

                if(fl_ToLoad_7)

                {

                                fl_Loader_7 = new Loader();

                                fl_Loader_7.load(new URLRequest("NAV01BBEC293.swf"));

                                addChild(fl_Loader_7);

                                fl_Loader_7 .x = 19;

                                fl_Loader_7 .y = 67;

                }

                else

                {

                                fl_Loader_7.unload();

                                removeChild(fl_Loader_7);

                                fl_Loader_7 = null;

                }

                // Toggle whether you want to load or unload the SWF

                fl_ToLoad_7 = !fl_ToLoad_7;

}

 

Main_btn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame_9);

function fl_ClickToGoToAndPlayFromFrame_9(event:MouseEvent):void

{

                gotoAndPlay(1);

}

 

The .swf file plays and when I click “Return to the Main Menu” button, only certain items display from frame 1. The .swf file is still loaded hiding the items that should display on frame 1. I have attached a screen shot of what happens when I click the "Return to Main Menu" button.After_click_Main_Menu button.png

 

Here is a screen shot of what frame 1 should look like.

 

Frame_1.png

 

I am on a very tight deadline so any assistance would be most appreciated!

 
Replies
  • Currently Being Moderated
    Mar 31, 2012 12:53 PM   in reply to bb_eLL_designer

    When you dynamically add content to a timeline, it does not have a home in any frame of that timeline - so it will persist wherever else you go in that timeline unless you remove it (or anchor it to something that is bound to a frame such as an empty movieclip that you place there).

     

    Try unloading the swf before you go to another frame...

     

    function fl_ClickToGoToAndPlayFromFrame_9(event:MouseEvent):void

    {

             fl_Loader_7.stopAndUnload();

             removeChild( fl_Loader_7);

             gotoAndPlay(1);

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 31, 2012 4:09 PM   in reply to bb_eLL_designer

    It looks like I got the command backwards (or Adobe did when they named it)...

     

    try...  fl_Loader_14.unloadAndStop();

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 2, 2012 8:27 AM   in reply to bb_eLL_designer

    If the main swf file is not in the same folder as the html page that embeds it, then you needs to adjust how it targets any files it loads.  The html page dictates the targeting reference for anything that it contains, so the swf has to target files as if it is in the same folder as the html page ... it doesn't have to be in that folder, it just has to act like it is.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 3, 2012 10:02 AM   in reply to bb_eLL_designer

    That should not be necessary.  You might need to reread what I wote.  The location needs are driven by the html page that you load the main swf into.

     

    If you embed the main file using something like...

     

    "flashfolder/main.swf"

     

    meaning the html page is in a different folder than the main file, and your other swf's are in the same folder as the main, then your main file will also have to target the files it loads using...

     

    "flashfolder/otherfile.swf"

     

    because when it is embedded in the html page, it is as good as living in its folder.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points