# \[FMX\] naming the mcs from an array w/ attachMovie

**URL:** <https://forum.kirupa.com/t/fmx-naming-the-mcs-from-an-array-w-attachmovie/8800>\
**Category:** Uncategorized\
**Created:** [November 28, 2002, 8:31pm UTC](https://forum.kirupa.com/t/fmx-naming-the-mcs-from-an-array-w-attachmovie/8800 "2002-11-28T20:31:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mr\_X](https://avatars.discourse-cdn.com/v4/letter/m/22d042/32.png) [@Mr\_X](https://forum.kirupa.com/u/Mr_X)\
**Post date:** [November 28, 2002, 8:31pm UTC](https://forum.kirupa.com/t/fmx-naming-the-mcs-from-an-array-w-attachmovie/8800/1 "2002-11-28T20:31:08Z")

</div>

OK, I posted that in the wrong forum… Waz late and I messed up… Mederator: feel free to delete the duplicate post in “Flash MX” thread. THX! Here it is:

ok, that’s some basic question but it’s 4 am, I can’t find the answer in the tutz and I’m starting to get a headache…  
I’m creating some mc’s on the stage with the attachMovie function in a loop. I have no problem naming them like that:

foo.attachMovie(“myClip”, “myClip”+i, 200+i);

But I need to name them with part of an array like that:

foo.attachMovie(“myClip”, “myClip”+array\*+"\_mc", 200+i);

I thought that would work but I guess my synthax is wrong… How do you mix strings and arrays elements inside the () of the attachMovie?

I need to get something like: myClipArrayElement1\_mc for the name of the attached movies…

THX!

* * *

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 29, 2002, 2:36am UTC](https://forum.kirupa.com/t/fmx-naming-the-mcs-from-an-array-w-attachmovie/8800/2 "2002-11-29T02:36:04Z")

</div>

nothing wrong with your syntax …

chances are that you’re referencing the array incorrectly.

what surrounds this code? where is it? where is your array?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 29, 2002, 2:56am UTC](https://forum.kirupa.com/t/fmx-naming-the-mcs-from-an-array-w-attachmovie/8800/3 "2002-11-29T02:56:40Z")

</div>

hi sbeener! nice to “see” you 😉  
I finally have a few days off to work on the same project you already helped me with… I’m adding some animation to those buttons created from the arrays… So I wanted to name the attached clips with the array elements names being part of their instance names instead of just button1, button2, etc… I couldn’t figure it out, so I kept the “myClip”+i format and I did something really not elegant to get the animation to work like that:

```auto
m.onEnterFrame = function() {
			if (_root.subCatArrow == "subCatArrow"+[this._name.charAt(this._name.length-1)]) {
				this["arrow_ANIM"+[this._name.charAt(this._name.length-1)]].nextFrame();
			} else {
				this["arrow_ANIM"+[this._name.charAt(this._name.length-1)]].prevFrame();
			}
		};

```

I’m sure you’d do the same with a nice looking prototype but I can’t really get the hang of those yet… And I don’t have time to practice, I wanna get this site done 🙂 The animation has some kinda arrow looking thing, hence the name of the variables…  
Now, I’m contemplating how to fade out the old buttons instead of using the removeMovieClip thing… But I have no idea how yet 🙂 Ho well… No sleep for me again tonight!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 29, 2002, 3:16am UTC](https://forum.kirupa.com/t/fmx-naming-the-mcs-from-an-array-w-attachmovie/8800/4 "2002-11-29T03:16:57Z")

</div>

when you write: \_root.oldButtons = [];

you just creating an empty array right?

and I don’t really get that part:

MovieClip.prototype.subCat\_BTcreate = function(subCat\_array) {  
var i, m;  
for (i in \_root.oldButtons) {  
removeMovieClip(\_root.oldButtons\*);  
}  
for (i=0; i\<subCat\_array.length; i++) {  
m = this.attachMovie(“subCat\_BT”, “subCat\_BT”+i, 100+i);  
\_root.oldButtons.push(m);  
m.\_x = \_root.marker2\_mc.\_x-m.\_width-2;  
m.\_y = 358-(m.\_height\*(i+1));  
m.\_alpha = 1;  
m.addText(subCat\_array\*);

the for in is still kinda mysterious to me, and I tried to understad the .push thing but I thought it was for arrays andt you use it on the variable m  
If you have time to explain, I’d love to learn faster than usual (meaning on my own 😉 thx.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 29, 2002, 5:20am UTC](https://forum.kirupa.com/t/fmx-naming-the-mcs-from-an-array-w-attachmovie/8800/5 "2002-11-29T05:20:11Z")

</div>

yes, [] creates a new, empty array.

push means add an item to the end of an array. that command is pushing m onto \_root.oldButtons.

the idea is to create an array which contains a reference to each button you create. then when you need to clear them, just run removeMovieClip on everything in the array.

that onEnterFrame event… you want all of the buttons to be running that so that their arrows will animate when they’re selected? what’s the code that sets \_root.subCatArrow?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 29, 2002, 5:36am UTC](https://forum.kirupa.com/t/fmx-naming-the-mcs-from-an-array-w-attachmovie/8800/6 "2002-11-29T05:36:40Z")

</div>

i’ve gotta go. good luck with tonight. i’ll check in tomorrow.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 29, 2002, 9:13am UTC](https://forum.kirupa.com/t/fmx-naming-the-mcs-from-an-array-w-attachmovie/8800/7 "2002-11-29T09:13:35Z")

</div>

4 am, all is working and beautiful…  
solved all my problems… for now… 😉  
Thanks for listening thought 🙂
