views:

16

answers:

2

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
        // ...
    }

}
A: 

FlashBuilder autocompletion will give you all the constant on your class and much more.

http://www.adobe.com/products/flashbuilder/

Julien
I'm not interested at all to get the list while i'm writing! Runtime to check I've passed a understandable value.
yuri
+1  A: 

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.

Joony
woah! An array is surely quicker! But reading the class definition I'm sure that I do not forget to update values in two places. Thanks.
yuri