7 Replies Latest reply: Apr 3, 2012 10:02 AM by Ned Murphy RSS

    Cannot unload external .swf and return to frame 1

    bb_eLL_designer Community Member

      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!

        • 1. Re: Cannot unload external .swf and return to frame 1
          Ned Murphy MVP

          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);

          }

          • 2. Re: Cannot unload external .swf and return to frame 1
            bb_eLL_designer Community Member

            I have been able to figure out how to get back to frame 1 from the .swf file. Here is the code I used:

             

            Main_btn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame_90);

             

            function fl_ClickToGoToAndPlayFromFrame_90(event:MouseEvent):void

            {

                    fl_Loader_14.unload();

                    removeChild(fl_Loader_14);

                    fl_Loader_14 = null;

                    gotoAndPlay(1);

            }

             

            Now I can't get the swf to stop playing. Can anybody help with that?

            • 3. Re: Cannot unload external .swf and return to frame 1
              Ned Murphy MVP

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

               

              try...  fl_Loader_14.unloadAndStop();

              • 4. Re: Cannot unload external .swf and return to frame 1
                bb_eLL_designer Community Member

                Thanks for that information, it was exactly what I needed. Now I have one more issue, my Flash files works perfectly when testing in Flash. When I put it on our webserver, the main .swf file opens just fine, but none of my .swf files play when I select it from the main .swf file. I have all of my .swf files in the same location since that is how I coded the Flash file and I have tried a couple of things to make it work to no success. Any ideas?

                • 5. Re: Cannot unload external .swf and return to frame 1
                  Ned Murphy MVP

                  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.

                  • 6. Re: Cannot unload external .swf and return to frame 1
                    bb_eLL_designer Community Member

                    Thanks for the help, but I did have all of the .swf files in the same folder. That turned out to be the problem, the swf files needed to be in a different location than the main .swf file. I can't explain why that is the case, but as long as it works (which it does) I am happy.

                    • 7. Re: Cannot unload external .swf and return to frame 1
                      Ned Murphy MVP

                      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.