AS3 - How can I get an array of constants of a class?

前端 未结 1 477
無奈伤痛
無奈伤痛 2021-02-09 15:23
static public const CONST_1 :String = \"CONST_1\";
static public const CONST_A :String = \"CONST_A\";

public var constantsArr :Array;

Is it possible t

相关标签:
1条回答
  • 2021-02-09 15:56

    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"));
    }
    
    0 讨论(0)
提交回复
热议问题