如何列出类中定义的所有 const 属性
我如何列出类中定义的公共(和私有/受保护)常量的所有名称(和值)?
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
// ...
}
}
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
// ...
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这适用于 as3 和 flex 4.5.1
This works with as3 and flex 4.5.1
在运行时,您可以使用describeType()列出所有公共变量(不太确定常量),以及更多信息。
http://www.adobe.com/livedocs /flash/9.0/ActionScriptLangRefV3/flash/utils/package.html#describeType()
私有更难获取。
不确定创建常量数组然后使用 array.indexOf(type) 是否会更快
PS 我也相信现在某个地方有一个 JSON 版本的describeType()。
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.
FlashBuilder 自动完成将为您提供类中的所有常量以及更多信息。
http://www.adobe.com/products/flashbuilder/
FlashBuilder autocompletion will give you all the constant on your class and much more.
http://www.adobe.com/products/flashbuilder/