# MX: dynamic duplicate & remove of MovieClips

**URL:** <https://forum.kirupa.com/t/mx-dynamic-duplicate-remove-of-movieclips/158363>\
**Category:** flash\
**Created:** [August 9, 2005, 10:34am UTC](https://forum.kirupa.com/t/mx-dynamic-duplicate-remove-of-movieclips/158363 "2005-08-09T10:34:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![CEOofAEP](https://avatars.discourse-cdn.com/v4/letter/c/7cd45c/32.png) [@CEOofAEP](https://forum.kirupa.com/u/CEOofAEP)\
**Post date:** [August 9, 2005, 10:34am UTC](https://forum.kirupa.com/t/mx-dynamic-duplicate-remove-of-movieclips/158363/1 "2005-08-09T10:34:26Z")

</div>

I continue to surprise myself with the things that I don’t know ^^

Here’s the deal: thanks to the help of many nice people here on the forum, I ended up with a relatively stable code. I have a for-loop that creates instances / duplicates of a movie clip that works like a charm:

```auto
for (pg = 0; pg < arr_tmp.length; pg++) {
var goalRef:String = "goal_" + arr_tmp[pg];
duplicateMovieClip(_root.theBall, goalRef, _root.getNextHighestDepth())
var gmc = eval("_root." + goalRef);
}

```

Then I position each instance- and I fill an array with the number (“pg”), because:

I also have the option to switch to a different view and at that point I want / need the MoveClips to disappear. So I have a function tied to the switching that goes through a loop for all instances of the movieclip copies (using the array with the IDs from the example above) and remove them.

```auto
for (t2 = 0; t2 < _root.array_all_goals.length; t2++) {
var goalRef:String = "goal_" + _root.array_all_goals[t2];
_root[goalRef].removeMovieClip();
}

```

…it doesn’t work. They stick around.

It _does_ work if I use “\_visible = false;” instead of “removeMovieClip()”- so the code and phrasing should be right (right?)- but why does one work and the other doesn’t?

And is it even advisable to remove the MCs instead of just hiding them until the next time i need them? Your input is very welcome.

Thanks in advance!  
~Marcel
