我怎么能列出所有在一个类中定义的常量属性常量、类中、属性、定义

2023-09-08 15:27:31 作者:你不來我不老

我怎么能列出所有在一个类中定义的名称(和值),公共(和私营/保护)const的吗?

 公共类图层{

    公共常量背景:字符串=背景;
    公共常量家长:字符串=父;
    公共常量MAP:字符串=地图;
    公共常量台词:字符串=行;
    公共常量要点:字符串=点;
    公共常量WINDOWS:字符串=窗口;

    ...

    公共职能isValidValue(类型:字符串){
        // ...
        //如果类型是恒定的返回值为TRUE
        // ...
    }

}
 

解决方案

在运行时,您可以使用describeType()全面列出所有的公共瓦尔(不太确定consts),和一大堆的详细信息了。

http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/utils/package.html#describeType()

私人表演都比较棘手的。

不知道它不会更快地创建常量数组,然后使用array.indexOf(类型)

P.S。我也相信有一个JSON的版本不如describeType(中)现在某个地方。

How can i list all the names (and values) of public (and private / protected) const defined in a class ?

public class Layers {

    public const BACKGROUND:String = "background";
    public const PARENT:String = "parent";
    public const MAP:String = "map";
    public const LINES:String = "lines";
    public const POINTS:String = "points";
    public const WINDOWS:String = "windows";

    ... 

    public function isValidValue(type:String) {
        // ...           
        // if type is a value of a constant return TRUE
        // ...
    }

}
TP5资源路径常量定义和使用

解决方案

At runtime, you can use describeType() to list all the public vars (not too sure about consts), and a whole lot more info too.

http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/utils/package.html#describeType()

Privates are more tricky to get.

Not sure if it wouldn't be quicker to create an array of the constants and then use array.indexOf(type)

P.S. I also believe there is a JSON version of describeType() now, somewhere.

 
精彩推荐
图片推荐