Naming MCs and setting properties

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

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…


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

Let me know… Oh, please use code formatting next time… =)

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


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. :slight_smile:

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… :-\

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

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.

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

pom :cowboy:

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