views:

28

answers:

1

I have this class

package somePackage
{
    public class SomeClass
    {
        public static const FOO: SomeClass = new SomeClass("0");
        public static const BAR: SomeClass = new SomeClass("1");
        }
}

I want to be able to get those static property given it's name.

Example:

public static function getProperty(propertyName: String): SomeClass {
    //don't know what goes here
}

var property1:SomeClass = SomeClass.getProperty("FOO"); // property1 == SomeClass.FOO
var property2:SomeClass = SomeClass.getProperty("BAR"); // property2 == SomeClass.Bar
+2  A: 

You could use square brackets like this:

SomeClass['FOO'] 

Or if you want to put it in a method that returns a typed object:

public static function getProperty(propertyName: String):SomeClass {
    return SomeClass[propertyName]
}
jeremynealbrown