Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 ];
like image 650
sanchez Avatar asked Jul 21 '12 22:07

sanchez


1 Answers

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"));
}
like image 200
Barış Uşaklı Avatar answered Oct 19 '22 04:10

Barış Uşaklı