# Naming MCs and setting properties

**URL:** <https://forum.kirupa.com/t/naming-mcs-and-setting-properties/14169>\
**Category:** Uncategorized\
**Created:** [February 22, 2003, 8:29pm UTC](https://forum.kirupa.com/t/naming-mcs-and-setting-properties/14169 "2003-02-22T20:29:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mojoNYC](https://avatars.discourse-cdn.com/v4/letter/m/b5a626/32.png) [@mojoNYC](https://forum.kirupa.com/u/mojoNYC)\
**Post date:** [February 22, 2003, 8:29pm UTC](https://forum.kirupa.com/t/naming-mcs-and-setting-properties/14169/1 "2003-02-22T20:29:17Z")

</div>

i have a problem whenever i name a movie and set its properties.  
whenever i use eval on the name it works,

function attachObj(){  
level++;  
myName=“object”+level;  
myName=eval(myName);  
myName.\_x=400;  
}

but when i try it this way it doesn’t:

level++;  
myName=“object”+level;  
attachMovie(“object”, myName, level);  
this[myName].\_x=400;

i’ve heard you shouldn’t use eval anymore because it’s deprecated, and that you should use this[object].\_property instead, but it’s not working for me–am i doing it wrong? can someone please shed a little light on this for me?  
thks,  
-mojo

---

<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:** [February 23, 2003, 5:18am UTC](https://forum.kirupa.com/t/naming-mcs-and-setting-properties/14169/2 "2003-02-23T05:18:20Z")

</div>

Howdy…

I am not sure if this is going to work or not, but here we go… Try this and see if it works or not…

```auto

level++;
myName="object"+level;
newMC = attachMovie("object", myName, level);
newMC._x=400;

```

Let me know… Oh, please use [code formatting](http://www.kirupaforum.com/misc.php?action=bbcode#buttons) next time… =)

---

<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:** [February 23, 2003, 7:40am UTC](https://forum.kirupa.com/t/naming-mcs-and-setting-properties/14169/3 "2003-02-23T07:40:26Z")

</div>

Try this out for size… You have newMC = attachMovie… That won’t work…

```php

level++;
myName = "object"+level;
new.attachMovie("object", myName, level);
newMC._x = 400;

```

Use the dot and not the equal since attachMovie is a MovieClip.prototype function. 🙂

---

<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:** [February 23, 2003, 9:45am UTC](https://forum.kirupa.com/t/naming-mcs-and-setting-properties/14169/4 "2003-02-23T09:45:06Z")

</div>

Umm… You made me to try the code, playamarz… I had no problem executing what I had, but I get to see this error

> Scene=Scene 1, Layer=Layer 1, Frame=1: Line 4: Unexpected ‘.’ encountered  
> new.attachMovie(“object”, myName, level);  
> with your code… :-\

---

<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:** [February 23, 2003, 6:17pm UTC](https://forum.kirupa.com/t/naming-mcs-and-setting-properties/14169/5 "2003-02-23T18:17:23Z")

</div>

thanks for the replies–what i’m trying to figure out, is there a ‘new’ way of naming instances and setting their properties? i can make it work either by using “object”+i or else ‘eval’, but i’m not sure about using this method:

myName=“object”+level;  
attachMovie(“object”, myName, level);  
this[myName].\_x=400;

any ideas about this style of naming/setting versus the ‘old’ way?  
thx,  
-mojo

---

<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:** [February 23, 2003, 9:46pm UTC](https://forum.kirupa.com/t/naming-mcs-and-setting-properties/14169/6 "2003-02-23T21:46:31Z")

</div>

Both should work. Now eval has been deprecated when it’s used on the left side of and equality, but not in general.  
Anyway, as I said, both sintaxes work.

```auto
var myName="object"+level;
this.attachMovie("object", myName, level);
this[myName]._x=400;

```

pom :cowboy:

---

<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:** [February 24, 2003, 6:09pm UTC](https://forum.kirupa.com/t/naming-mcs-and-setting-properties/14169/7 "2003-02-24T18:09:46Z")

</div>

that’s good to know–eval has always been my pet ‘secret’ method since i found out how to use it–i think a lot of folks have banged their head trying to name an instance that didn’t know about it…  
thanks for the exp, pom (-:

-mojo
