5 Replies Latest reply on Oct 25, 2012 8:20 AM by kglad

    How to remove duplicate attach movies on stage?

    enciel17

      Hi,

       

      I am currently making a starting game and is still learning actionscript. So far what I did was I have a different set of buttons

       

      For button01 - I added this script to it

       

      on (release) {

                i = i + 1;

                _root.attachMovie("flipitem01","flipitem01new" + i, i);

       

      }

       

       

      what happens is when i click button01 I duplicate the flipbed02 movieclip and call it on stage as many times the user wants it.

       

      I set this item on different buttons to call in other duplicate movie clips. Everything is as I want it to be. But the problem is I want to create a clear button.

      I want to be able to clear all the duplicated items that is called onto the stage. I tried removeMovieClip but it's not working.

       

      The only one working I have tried was sto add a _root.unloadMovie(); on the clear button but the problem is it clears everything in the stage including the background and stuffs. So any help is appreciated!

        • 1. Re: How to remove duplicate attach movies on stage?
          kglad Adobe Community Professional & MVP

          your new movieclips are _root["flipitem01new"+i].

           

          so, you would use:

           

          _root["flipitem01new"+i].removeMovieClip();

          1 person found this helpful
          • 2. Re: How to remove duplicate attach movies on stage?
            enciel17 Level 1

            I tried this on the clear button and added this

             

            on(press){

                      _root["flipitem01new"+i].removeMovieClip();

            }

             

             

            it works but it won't clear all of them movieclips on stage. I have to click the clear button repeatedly so everything gets deleted, it's actually great! but is there a way to make it so that when i press the clear button every duplicated movieclip will be removed on the stage?

            • 3. Re: How to remove duplicate attach movies on stage?
              kglad Adobe Community Professional & MVP

              you need to iterate through the i variables that you used.

               

              if you don't understand what values of i you're using, you can use an array to store the created movieclips and iterate through that array.

              1 person found this helpful
              • 4. Re: How to remove duplicate attach movies on stage?
                enciel17 Level 1

                hi! can you give a sample on how to do it?

                 

                for example i have these 3 movie clips exported in action script in frame 1. (flipitem01, flipitem02, flipitem03)  and i duplicate them right? so the names of the duplicate will always have +i. right?

                 

                I have just a basic information on how to delcare an  array but haven't had much experience on it. I am new with this sorry..

                 

                Can you give a sample code for it? and this will be set in the clear button?

                • 5. Re: How to remove duplicate attach movies on stage?
                  kglad Adobe Community Professional & MVP

                  :

                   

                  for(var i:Number=1;i<=3;i++){

                  _root["flipitem0"+i].removeMovieClip();

                  }

                   

                  //////////////////////////

                   

                  but you're going to make mistakes and have trouble with this.  use an array:

                   

                  // attached to a frame:

                  _root.flipA = [];

                   

                  // and store your movieclips in that array.

                  on (release) {

                            i = i + 1;

                            var mc:MovieClip=_root.attachMovie("flipitem01","flipitem01new" + i, i);

                  _root.flipA.push(mc);

                  }

                   

                  // then whenever you want to remove all the existing flip movieclips, use:

                   

                  for(var i:Number=_root.flipA.length-1;i>=0;i--){

                  _root.flipA[i].removeMovieClip();

                  _root.flipA.splice(i,1);

                  }