3 Replies Latest reply on Dec 11, 2014 7:45 AM by sinious

    Help with load and unload swf file.


      hello, just now i try, to  load my file using the code snippet 'load and unload' i manage to load the next file succesfully but why my recent file still appear in the background? how do i make it gone?

        • 1. Re: Help with load and unload swf file.
          sinious Most Valuable Participant

          When you load another SWF you're loading it 'inside' the current SWF but it appears that you want to replace the current SWF entirely with the new SWF, is that correct?


          If so you should make what's usually known as a 'stub' or a loader. Make an empty project that merely acts as a loader. It should load your first SWF and when you press a button on that first SWF to load a second SWF, it should signal the 'stub' it's loaded inside to unload the first SWF and then load the second.


          e.g. a stub.swf (just coding out of memory, not error checked, just to give a general idea):


          // make a new loader to do all the loading of SWFs
          var loader:Loader = new Loader();
          // and display
          // a function to load a SWF into the loader (replacing any existing SWF)
          function loadSWF(path:String):void
               // assure path is defined or do nothing
               if (!path) return; 
               // load requested SWF
               loader.load(new URLRequest(path));     
          // load initial SWF

          For your 1.swf to use the function, you're currently inside the .content property of a Loader so I believe you can just run a command like: Object(this.parent.parent).loadSWF('/path/to/2.swf');

          This example obviously lacks any error checking or transitions but you can add those and season to taste.

          1 person found this helpful
          • 2. Re: Help with load and unload swf file.
            rudat Level 1

            ermm. the only problem is that the one with masking effect still remains in the background. no idea how to make it gone... 

            • 3. Re: Help with load and unload swf file.
              sinious Most Valuable Participant

              The Loader class has an unload() method. You can just run that before running a load():


              // ..

              // unload any existing



              // load new file

              loader.load(new URLRequest(path));

              // ..

              Loader class:

              Loader - Adobe ActionScript® 3 (AS3 ) API Reference

              1 person found this helpful