How can I call different mc's through variables?

I have a function that works great. All excep the inefficient way I have to do if checks just to change a movieclip name.

People = function(num) {
if (num ==1) {
Person1._x = lft_rght;
}

if (num ==2) {
Person2._x = lft_rght;
}
etc…}

Is there a proper form to pull off something like this:

People = function(num) {
“Person”+num = lft_rght;
}
etc…}

Thanks for any direction

Ron

yep it goes like this

People = function(num) {
_root[“Person”+num]._x = lft_rght;
}

notice that the dot in the OOP is there after the brackets but not before.

LOL… this concept, I know, will open up a bunch of doors in your head. Go with it. You’re on the way to creating everything dynamicaly, with that trick. :slight_smile:

It is not quite working for me.

So let’s say I want this line to be created:

back.pIcon1._x = 100;

Would I not use:

i = 1;
_root[“back.pIcon”+i]._x = 100;

Also, is the “_root” always needed? And why is there no “.” after it?

Thanks Ron

It is not quite working for me.

So let’s say I want this line to be created:

back.pIcon1._x = 100;

Would I not use:

i = 1;
_root[“back.pIcon”+i]._x = 100;

not quite. As I said, the example was for stuff located on the main timeline because of the _root thingy. When ever you are using the brackets to create a dynamic name inside an OOP object call you have to start from the _root and work your way up the string. You can also use parent to go back up the string, but I wont go into that yet.
In the above case you would use

i = 1;
_root.back[“pIcon”+i]._x = 100;

notice that the dot isn’t really taken out after the “_root” but before the first bracket. The reason is not entirely clear to me. It is possible that it is part of the structure of OOP because objects within other objects are sort of properties of the parents. Property names can be accessed like arrays in a/s. Arrays use brackets to name each of their elements. Not sure if that makes any sense at all, but just keep in mind the structure of it, and you really wont need to worry too much right now as to the whys. :slight_smile: