PDA

View Full Version : Parsing method name from a string variable


rademenes
03-20-2003, 06:30 AM
Hello,

OK, maybe not exactly from a string. What I'm trying to do is to use a for loop to go through around 60 or so instances of an object but I'm not sure what would be the syntax to access a particular instance. The code in question:


for(i = 0; i <= 60; i++)
{
// there are 60 instances of FOO (of type MovieClip)
// each instance has a unique name that is foo1, foo2, etc
// i tried this but this doesn't seem to work
setProperty(obj1.foo&i, _alpha, 0);
}

is it possible to concatenate a string and then use this string as the method name when trying to access it? Also, if there are two objects of type OBJ (obj1 and obj2), is it OK for them to have instances of FOO with the same name, that is obj1.foo111 and obj2.foo111?

CyanBlue
03-20-2003, 06:34 AM
Howdy and Welcome... ;)

Try this...for (i = 0 ; i <= 60 ; i++)
{
obj1["foo" + i]._alpha = 0;
}and yes... obj1.foo111 and obj2.foo111 are two different variables... ;)