AS3 - 我如何获得一个类的常量数组? [英] AS3 - How can I get an array of constants of a class?

查看:146
本文介绍了AS3 - 我如何获得一个类的常量数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 的静态公共常量CONST_1:字符串=CONST_1;
静态公共常量CONST_A:字符串=CONST_A;

公共变种constantsArr:阵列;
 

时有可能得到类的常量值的阵列,而无需手动添加它们是这样的:

  constantsArr = [CONST_1,CONST_A]。
 

解决方案

使用不如describeType它应该是可能的:

 公共类常量
{
    静态公共常量CONST_1:字符串=CONST_1;
    静态公共常量CONST_A:字符串=CONST_A;
}

VAR的XMLList:返回XMLList =不如describeType(常量).child(恒);

VAR constantsArray:数组= [];
每个(VAR键:XML中的XMLList)
{
   constantsArray.push(key.attribute(名字));
}
 

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 ];

解决方案

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"));
}

这篇关于AS3 - 我如何获得一个类的常量数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆