View Full Version : naming MCs and setting properties
mojoNYC
February 22nd, 2003, 03:29 PM
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
CyanBlue
February 23rd, 2003, 12:18 AM
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 (http://www.kirupaforum.com/misc.php?action=bbcode#buttons) next time... =)
Marz
February 23rd, 2003, 02:40 AM
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. :)
CyanBlue
February 23rd, 2003, 04:45 AM
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... :-\
mojoNYC
February 23rd, 2003, 01:17 PM
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
pom
February 23rd, 2003, 04:46 PM
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:
mojoNYC
February 24th, 2003, 01:09 PM
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
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.