actionscript-3 - AS3-如何获取类的常量数组?

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

最佳答案

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

关于actionscript-3 - AS3-如何获取类的常量数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11596475/

相关文章:

actionscript-3 - 为什么 Actionscript 3 ENTER_FRAME 事件如此疯狂?

javascript - 当 wmode=window 时,如何将 html 内容放在 flash 上?

flash - 在 HTML 5 Canvas Animate CC 文档中包含代码文件

apache-flex - Flexunit 与 Flex Builder 3 中的纯 ActionScript 项目

apache-flex - 弱引用和强引用

apache-flex - ActionScript 3 : Use an argument as a type?

flash - AS3 : How to find the parent of a deep-nested Sprite from the Stage?

actionscript-3 - AS3 Air — 检查 Zip 以获取音频文件

c# - 使用 C# 图形从 swf 中绘制图像

flash - Actionscript:为什么可以在声明之前分配变量?