creating a dynamically named object
I'm trying to create a dynamically named object.
something like
private var myVar:String = "dynamicName";
private var [myVar+"staticName"]:Object = new 开发者_高级运维Object;
but what i wrote above dosn't work for some reason.
I'd be very surprised if you get that to work.
Better to save your dynamically created objects in an array or possibly a Dictionary. The Flex Framework uses Arrays for itemRenderers in list based classes, for example. Try something like this using a Dictionary:
private var myObjects : Dictionary = new Dictionary()
In some method where you create the children:
private var myVar:String = "dynamicName";
myObjects[myVar+"staticName"] = new Object();
You could try something like this:
var myDynamicObjects:Object = new Object();
var myVar:String = "dynamicName";
myDynamicObjects[myVar + "staticName"] = new Object();
Using square brackets allows you to manipulate dynamic object properties.
== Edit ==
Better yet, like @www.Flextras.com says, use a dictionary or an array.
精彩评论