AS3 - 如何获得类的常量数组?

时间:2012-07-21 22:56:07

标签: actionscript-3 flash actionscript

static public const CONST_1 :String = "CONST_1";
static public const CONST_A :String = "CONST_A";

public var constantsArr :Array;

是否可以获取类常量值的数组,而无需像下面这样手动添加它们:

  constantsArr = [ CONST_1, CONST_A ];

1 个答案:

答案 0 :(得分:14)

使用describeType应该是可能的:

public class Constants
{
    static public const CONST_1 :String = "CONST_1";
    static public const CONST_A :String = "CONST_A";
}

var xmlList:XMLList = describeType(Constants).child("constant");

var constantsArray:Array = [];
for each(var key:XML in xmlList)
{
   constantsArray.push(key.attribute("name"));
}