Arrays 从AS3中的数组值实例化类对象

Arrays 从AS3中的数组值实例化类对象,arrays,class,actionscript-3,object,Arrays,Class,Actionscript 3,Object,我试图在一个循环中创建新的类实例,其中类实例名称已在数组中定义。如何将数组值从字符串转换为对象?这是我到目前为止写的 var tiles2:Array=新数组(“e1”、“e2”、“e3”和…) 如果您有更好的操作程序,如果您能给我看一下,我将非常高兴。我相信您正在寻找这个 // If tiles2[i] is a string that is the name of a class var type:Class = getDefinitionByName(tiles2[i]) as Class

我试图在一个循环中创建新的类实例,其中类实例名称已在数组中定义。如何将数组值从字符串转换为对象?这是我到目前为止写的

var tiles2:Array=新数组(“e1”、“e2”、“e3”和…)


如果您有更好的操作程序,如果您能给我看一下,我将非常高兴。

我相信您正在寻找这个

// If tiles2[i] is a string that is the name of a class
var type:Class = getDefinitionByName(tiles2[i]) as Class;
var thing = new type();

// If tiles2[i] is a string instance name for an existing object:
var thing:DisplayObject = getChildByName(tiles[i]);
或者,您可能只需要将相关行更改为:

//var mc = new tiles2[i]; <-- line in question

//take out the var, and instantiate the proper class
this[tiles2[i]] = new e1();

//var mc=new tiles2[i]
tiles2
只是我创建的一个数组,它保存在我的资产库中的stage上创建的对象的名称。它不是类的名称file@NelsonSule-不清楚你的代码中有什么内容-这个答案看起来是为了解释你想做什么-因为它显然不是,所以我猜了一下并把它添加到了这个答案中。或者他甚至可能想要
var tileClassname:String=getQualifiedClassName(这个[tiles2[I]]);var tileClass:Class=getDefinitionByName(tileClassname)作为类;var newfile=new tileClass()@kaarto感谢您的回复。我在stage上创建了具有链接类名的资产,如
e1、e2
。。。我正在寻找一种方法来轻松地自动化这个繁琐的过程,而不是编写一个代码来逐个创建每个实例。所以我创建了一个名为tiles2=[“e1”,“e2”,…]的资产数组
。现在,我想要实现的是将数组中的每个字符串转换为变量名和类标识符,例如
var e1=new e1()
对于arraySo的所有值,这些是链接名称吗?那么Andrew的第一个解决方案应该适合你,你测试过了吗?
// If tiles2[i] is a string that is the name of a class
var type:Class = getDefinitionByName(tiles2[i]) as Class;
var thing = new type();

// If tiles2[i] is a string instance name for an existing object:
var thing:DisplayObject = getChildByName(tiles[i]);
//var mc = new tiles2[i]; <-- line in question

//take out the var, and instantiate the proper class
this[tiles2[i]] = new e1();