3 Replies Latest reply on Dec 14, 2010 12:51 PM by richardl7

    Unload swf in Flash Pro

    Tonangel

      I publish a swf from a Catalyst Project and then load it in Flash Pro using the prebuild code snippet:

       

       

      myButton.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF);

       

      var fl_Loader:Loader;

       

      function fl_ClickToLoadUnloadSWF(event:MouseEvent):void

      {

      if(fl_ToLoad)

      {

      fl_Loader = new Loader();

      fl_Loader.load(new URLRequest("Main.swf"));

      addChild(fl_Loader);

      }

      else

      {

      fl_Loader.unload();

      removeChild(fl_Loader);

      fl_Loader = null;

      }

      fl_ToLoad = !fl_ToLoad;

      }

       

       

      The swf is loaded but if i click the button again, the swf is not unloaded.

       

      I have used this code before with an swf created in flash and work fine but cant make it work with catalyst swf.

        • 1. Re: Unload swf in Flash Pro
          SrinivasAnnam Adobe Employee

          Hi,

           

             I hope that you declared "fl_ToLoad" variable outside the function. See the sample below:

           

                            var fl_ToLoad:Boolean=true;

           

            Once I declared this variable, the same code was working for me with Catalyst / Non-catalyst SWFs.

           

          Regards

          Srinivas Annam

          • 2. Re: Unload swf in Flash Pro
            Tonangel Level 1

            Thank you Srinivas, but i cant unload Catalyst swf. Thats my code now:

             

            myButton.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF);

             

            var fl_Loader:Loader;

             

            var fl_ToLoad:Boolean=true;

             

            function fl_ClickToLoadUnloadSWF(event:MouseEvent):void

            {

            if(fl_ToLoad)

            {

            fl_Loader = new Loader();

            fl_Loader.load(new URLRequest("Main.swf"));

            addChild(fl_Loader);

            }

            else

            {

            fl_Loader.unload();

            removeChild(fl_Loader);

            fl_Loader = null;

            }

            fl_ToLoad = !fl_ToLoad;

            }

            • 3. Re: Unload swf in Flash Pro
              richardl7

              Save the loader and use unloadAndStop(true);


                  var myContainer:Loader = new Loader();
                  var myURL:URLRequest=new URLRequest("game.swf")
                  myContainer.load(myURL);
                  addChild(myContainer);

               

              Later:

                  myContainer.unloadAndStop(true);