How can I list all const properties defined in a class

How can I list all the names (and values) of the public (and private / protected) const defined in the 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 // ... } } 
0
source share
3 answers

At run time, you can use describeType () to list all public vars (not too confident about consts) and more.

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

Private individuals are more complex.

Not sure if it will be faster to create an array of constants and then use array.indexOf (type)

PS I also believe that there is now a JSON version of the type () description somewhere.

+1
source

This works with as3 and flex 4.5.1

 public static function isValidValue(type:String):Boolean { var m_constNameList:XMLList = describeType(Layers).descendants("constant"); for each(var obj:Object in m_constNameList){ if (type == Layers[ obj.@name ]){ return true; } } return false; } 
+2
source

AutoFill FlashBuilder will give you all the constant in your class and much more.

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

0
source

Source: https://habr.com/ru/post/921047/


All Articles