Comments: reader mail: dynamic variable names

You can also use the 'set' command:

//-- use the set command
function MyClass () {}
myClass.prototype.hello = function() {
trace( "hello world" );
}

for ( i=0; i<=3; i++ ) {
set( "myobjectinstancename" + i, new myClass() );
}

myobjectinstancename1.hello(); // Displays "hello world"
myobjectinstancename2.hello(); // Displays "hello world"
myobjectinstancename3.hello(); // Displays "hello world"

Posted by Scott Janousek at July 18, 2003 01:10 AM

I think what Stefan is asking for is more like this:

var iname = "myobjectinstancename";
this[iname] = new myClass();

myobjectinstancename.hello(); // Displays "hello world"

This also works. Right?

Posted by D Schafer at July 10, 2003 01:07 PM

you can also concatenate strings or get objects properties

obj_01 = new Object();
obj_01.value = 100;
//
objnum = 01;
trace(this["obj_"+objnum].value); // Displays 100

Posted by sangles at July 9, 2003 04:08 PM