PDA

View Full Version : adding properties to an object


Flippie124
02-01-2005, 08:56 AM
I'd like to add properties to an object but the property names are defined in another variable.

in this piece of code I added "someproperty" to the object t:

var t:Object = new Object();
t.someproperty = "aap"
trace(t.someproperty);

what I want to do is this:

var propertyname = "someproperty";
var t:Object = new Object();
t.(propertyname) = "aap" // of course this doesn't work :(
trace(t.someproperty);

So the name of the property is extracted from the value of another variable.

ain
02-01-2005, 09:00 AM
A simple sample for you:

var prop = "sh";
var obj = new Object();
obj[prop] = "Some value";
trace(obj.sh);

Flippie124
02-01-2005, 12:05 PM
tnx mate!

ain
02-01-2005, 12:54 PM
You are welcome. Glad to help