create arraycollection with different name

拟墨画扇 提交于 2019-12-12 01:36:34

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/6001385/create-arraycollection-with-different-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!