AS3 - How can I get an array of constants of a cla

2019-03-20 13:28发布

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

public var constantsArr :Array;

Is it possible to get an array of the class constant values without adding them manually like this:

  constantsArr = [ CONST_1, CONST_A ];

1条回答
成全新的幸福
2楼-- · 2019-03-20 13:59

Using describeType it should be possible :

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"));
}
查看更多
登录 后发表回答