Skip to main content
Participating Frequently
October 23, 2012
Answered

How to remove duplicate attach movies on stage?

  • October 23, 2012
  • 1 reply
  • 960 views

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!

This topic has been closed for replies.
Correct answer kglad

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?


:

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.removeMovieClip();

_root.flipA.splice(i,1);

}

1 reply

kglad
Community Expert
Community Expert
October 23, 2012

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

so, you would use:

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

enciel17Author
Participating Frequently
October 23, 2012

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?

kglad
Community Expert
Community Expert
October 23, 2012

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.