I would like to create a new AC instance with a dynamic variable which is nca1开发者_如何学C, nca2, etc. Without define using hardcode variable name, it is possible to do that in a loop?
I'm afraid you are missing the point here, getDefinitionByName gives you a class instance, you cannot create a variable with a dynamic name this way.
This is how you create an instance per reflection:
var symbolClass: Class;
var s: ArrayCollection;
symbolClass = getDefinitionByName("mx.collections.ArrayCollection") as Class;
s = new symbolClass();
If you wan't to have dynamic variables you'd better look at Dictionary and use it to save your values using strings as keys.
EDIT
You have now removed the code snippet, so that for others my code may doesn't make sense: but you know what I mean at least.
Dynamic variables in a loop is a different question - still you could use a Dictionary to save your data and yes you could dynamically create its content in a loop.
精彩评论