Package COM. shine. framework. core. util {import flash. utils. describetype; import flash. utils. getdefinitionbyname; import flash. utils. getqualifiedclassname; import flash. utils. getqualifiedsuperclassname; import MX. utils. nameutil; import MX. collections. arraycollection; import MX. controls. alert; public class referenceutil {public function referenceutil () {}/*** get the Class Object package: classname **/Public stat IC function referenceclass (classname: string): object {var classreference: class = getdefinitionbyname (classname) as class; var instance: Object = new classreference (); Return instance ;} /*** get the value of class **/public static function referenceclassparameters (classname: String, parameters: string): * {return referenceclass (classname) [parameters];} /*** execution method **/public static function referenceclassfunction (CLAS Sname: String, functionname: String ,... rest): * {var instance: Object = referenceclass (classname); Return instance [functionname]. apply (instance, rest);}/*** execution method **/public static function referenceobjectfunction (instance: object, functionname: String ,... rest): * {return instance [functionname]. apply (instance, rest);}/*** get the full name of class name **/public static function getclassfullname (value: Object): String {return Getqualifiedclassname (value);}/*** get class name **/public static function getclassname (value: Object): String {If (getqualifiedclassname (value ). indexof ("::")! =-1) return getqualifiedclassname (value ). substring (getqualifiedclassname (value ). indexof (":") + 2); elsereturn getclassfullname (value);}/*** get all function lists * PS: only the name of the de-method can be obtained, you cannot obtain protected and private **/public static function getallfunctionfromobject (instance: Object): arraycollection {var functionarraycollection: arraycollection = new arraycollection; VaR method: xmllist = describetype (instance ). method; var num: Int = method. length (); For (var I: Int = 0; I <num; I ++) {var XML: xml = method [I]; functionarraycollection. additem (XML. @ name); xml = NULL;} return functionarraycollection ;}}}
It is estimated that few people use flex reflection because of its compilation mode, which makes reflection feel less flexible than Java, but in many places, its reflection is very practical. Obtain at least all functions of an object and then call them dynamically based on the function. I hope you can come up with good comments.