programmatically add property do ActionScript Object (metaprogramming)
Asked Answered
L

1

6

I have an AS3 Object: {p1:"..", p2:".."} I want con create another object that contains the first one in a property whose name is defined by a variable:

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

does it make any sense?

Laborious answered 2/8, 2009 at 21:10 Comment(2)
This is not really metaprogramming. I do not know the exact word, but it is posible because actionscript is a dynamic language.Blatman
you're right.. I never really understood what metaprogramming was, I'll read some more about it!Laborious
P
15
var propertyName:String = "myName";
var myObj = new Object();
myObj[propertyName] = {p1:"..", p2:".."};
Peskoff answered 2/8, 2009 at 21:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.