7 Replies Latest reply on Dec 11, 2011 4:34 PM by kglad

    remove external swf completely from memory

    anjemalo Level 1

      Hello:

       

      I have read many many post and I don't find the answer of how to remove completely a swf load external.

      Every time I load and unload I see the windows memory task manager and see that the memory increase and don't reduce when remove child.

      ¿Can you help me please?  thank you.

       

      this is my code:

       

      var oneLoader=new Loader();

      bt1.addEventListener(MouseEvent.CLICK, swf1);

      bt2.addEventListener(MouseEvent.CLICK, removeMe);

       

      function swf1(e:Event)

      {

       

      var oneLoader=new Loader();

      addChildAt(oneLoader,1);

      oneLoader.load(new URLRequest("swf1.swf"));

      }

      function removeMe(e:Event)

      {

       

      removeChildAt(1);

      oneLoader= null;

       

      }

        • 1. Re: remove external swf completely from memory
          kglad Adobe Community Professional & MVP

          :

           

          var oneLoader=new Loader();

          bt1.addEventListener(MouseEvent.CLICK, swf1);

          bt2.addEventListener(MouseEvent.CLICK, removeMe);

           

          function swf1(e:Event)

          {

           

          var oneLoader=new Loader();

          addChildAt(oneLoader,1);

          oneLoader.load(new URLRequest("swf1.swf"));

          }

          function removeMe(e:Event)

          {

          if(oneLoader){

          oneLoader.unloadAndStop();  // if publishing for fp 10+, else must explicitly stop all streams and apply unload().

          oneLoader.parent.removeChild(oneLoader);

          oneLoader= null;

          }

          }

          1 person found this helpful
          • 2. Re: remove external swf completely from memory
            anjemalo Level 1

            Thank you very much.

             

            My swf is a movieclip that make only a fade and stop, then load an still image that you can drag, zoom, etc.

            Do you think do I have to stop all streams....?

            If yes, how can I do it?

             

            what mean ...fp 10+ ...

             

            many thanks again.

            • 3. Re: remove external swf completely from memory
              kglad Adobe Community Professional & MVP

              fp 10+ =  flash player 10 or better.

               

              you don't have any streams to stop.  so, if you're publishing for fp 9, you can use oneLoader.unload();

               

              p.s.  please mark helpful/correct responses.

              1 person found this helpful
              • 4. Re: remove external swf completely from memory
                anjemalo Level 1

                Thank you very much.

                I have a last question.

                 

                In my external swf I have put a close button with this code:

                 

                btclose.addEventListener(MouseEvent.CLICK, CloseMe);

                function CloseMe(event:MouseEvent) {

                    MovieClip(parent.parent).removeMe(event);

                }

                stop();

                 

                 

                In the main movie i have te removeMe function that works perfectly when I close from the main, but not with the close buton of external swf, it seem does not access to the removeMe function, what is wrong here?

                 

                function removeMe(e:Event):void

                {

                    if (oneLoader)

                    {

                        oneLoader.unloadAndStop();

                        // if publishing for fp 10+, else must explicitly stop all streams and apply unload().;

                        oneLoader.parent.removeChild(oneLoader);

                        oneLoader.unload(); //    ..... I added, I'm use fp 11.

                        oneLoader= null;

                     }

                   }

                • 5. Re: remove external swf completely from memory
                  kglad Adobe Community Professional & MVP

                  1.  your external swf code needs to be on that swf's main timeline and

                   

                  2.  your removeMe() function needs to be on the timeline where oneLoader is created.

                  • 6. Re: remove external swf completely from memory
                    anjemalo Level 1

                    Thank you again.

                     

                    The code are on their right places.

                     

                    But When I close with the swf button close. The window is closed but not remove from memory.

                     

                    I have other button on the main movie (for try)  and when I push this: close the swf and remove form memory.

                    Do you know why I cannot remove from the swf button?

                     

                    thanks

                    • 7. Re: remove external swf completely from memory
                      kglad Adobe Community Professional & MVP

                      it makes no difference what's calling removeMe() so you must be doing something wrong or erroneously judging the swf is not removed from memory.