Programmatically add a do ActionScript Object property (metaprogramming)

I have an AS3 object: {p1: "..", p2: ".."} I want to create another object containing the first in the property, whose name is determined by the variable:

var propertyName:String = "myName";
var myObj = new Object();
myObj.something_that_creates_a_property_named_as_propertyName({p1:"..", p2:".."})

it makes sense?

+5
source share
1 answer
var propertyName:String = "myName";
var myObj = new Object();
myObj[propertyName] = {p1:"..", p2:".."};
+14
source

All Articles