创建的ArrayCollection有不同的名称 [英] create arraycollection with different name

查看:139
本文介绍了创建的ArrayCollection有不同的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有一个动态的变量,它是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.

这篇关于创建的ArrayCollection有不同的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆