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

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!


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?

hi sbeener! nice to “see” you :wink:
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:

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 :slight_smile: 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 :slight_smile: Ho well… No sleep for me again tonight!

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 :wink: thx.

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?

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

4 am, all is working and beautiful…
solved all my problems… for now… :wink:
Thanks for listening thought :slight_smile: