我想有一个动态的变量,它是nca1,nca2等创建一个新的交流的实例没有定义使用硬code变量名,这是可以做到的,在一个循环?
I would like to create a new AC instance with a dynamic variable which is nca1, nca2, etc. Without define using hardcode variable name, it is possible to do that in a loop?
我怕你缺少点这里,getDefinitionByName为您提供了一个类的实例,你不能创建一个动态名称这样的变量。
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();
如果您wan't有动态变量,你最好看一下字典,并用它使用字符串作为键,以节省您的值。
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.
修改
您现在已经删除了code段,让别人我的code可能没有任何意义:但你知道我的意思,至少。
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.