# How can I call different mc's through variables?

**URL:** <https://forum.kirupa.com/t/how-can-i-call-different-mcs-through-variables/6826>\
**Category:** Uncategorized\
**Created:** [October 17, 2002, 8:21am UTC](https://forum.kirupa.com/t/how-can-i-call-different-mcs-through-variables/6826 "2002-10-17T08:21:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![3dron](https://avatars.discourse-cdn.com/v4/letter/3/2acd7d/32.png) [@3dron](https://forum.kirupa.com/u/3dron)\
**Post date:** [October 17, 2002, 8:21am UTC](https://forum.kirupa.com/t/how-can-i-call-different-mcs-through-variables/6826/1 "2002-10-17T08:21:53Z")

</div>

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

---

<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:** [October 17, 2002, 8:26am UTC](https://forum.kirupa.com/t/how-can-i-call-different-mcs-through-variables/6826/2 "2002-10-17T08:26:11Z")

</div>

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. 🙂

---

<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:** [October 27, 2002, 11:23pm UTC](https://forum.kirupa.com/t/how-can-i-call-different-mcs-through-variables/6826/3 "2002-10-27T23:23:26Z")

</div>

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

---

<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:** [October 28, 2002, 4:43am UTC](https://forum.kirupa.com/t/how-can-i-call-different-mcs-through-variables/6826/4 "2002-10-28T04:43:16Z")

</div>

> 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. 🙂
