# Attach and remove movieclips

**URL:** <https://forum.kirupa.com/t/attach-and-remove-movieclips/239202>\
**Category:** Uncategorized\
**Created:** [September 19, 2007, 3:08pm UTC](https://forum.kirupa.com/t/attach-and-remove-movieclips/239202 "2007-09-19T15:08:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![petfactory](https://avatars.discourse-cdn.com/v4/letter/p/7ab992/32.png) [@petfactory](https://forum.kirupa.com/u/petfactory)\
**Post date:** [September 19, 2007, 3:08pm UTC](https://forum.kirupa.com/t/attach-and-remove-movieclips/239202/1 "2007-09-19T15:08:27Z")

</div>

Hi all and thanks 4 a great forum 🙂

I´ve got a problem that is really bugging me. I´ve got a function “addNavSquare” which works fine. it attaches a moveclip to the root and the number of clips is controlled by a .xml file. The movieclips works as an “index” to show different images. it all works fine…

[COLOR=gray]function addNavSquare() {[/COLOR]  
[COLOR=gray]for (var i = 0; i\<total; i++) {[/COLOR]  
[COLOR=gray]menuName = “menuSquare\_”+String(menuCount);[/COLOR]  
[COLOR=gray]menuDepth = this.getNextHighestDepth();[/COLOR]  
[COLOR=gray]this.attachMovie(“navigation\_box”,menuName,menuDepth,initMenuButton);[/COLOR]  
[COLOR=gray]this[menuName].\_number = menuCount;[/COLOR]  
[COLOR=gray]this[menuName].\_x = 210 + menuCount \* 15 ;[/COLOR]  
[COLOR=gray]this[menuName].\_y = 120;[/COLOR]  
[COLOR=gray]menuCount++;[/COLOR]  
[COLOR=gray]}[/COLOR]  
[COLOR=gray]}[/COLOR]

But !

when i try to remove the movieclips using the code below it wpont work !?

[COLOR=gray]function removeNavSquare() {[/COLOR]  
[COLOR=gray]trace (“deleted”);[/COLOR]  
[COLOR=gray]for(var i = 0; i \< menuCount; i++) {[/COLOR]  
[COLOR=gray]this[“menuSquare\_”+i].removeMovieClip();[/COLOR]  
[COLOR=gray]}[/COLOR]  
[COLOR=gray]}[/COLOR]

Í would be really greatful for any good tips or ideas !

Thanksalot Johan :puzzle:
