Actionscript - obtain method list for a given class name
I want to obtain a list of methods available to a c开发者_JAVA技巧lass, given its name. How can I do this?
This is called introspection, and AS3 has a limited ability to do introspection.
Here is about the best you can do,
import flash.utils.describeType;
var data:XML = (describeType(SingleEvent));
for each (var method:XML in data.factory.method) {
trace("Name: " + method.@name);
trace("Returns: " + method.@returnType);
for each (var parameter:XML in method.children()) {
trace("Parameter " + parameter.@index + ": " + parameter.@type + ", optional: " + parameter.@optional);
}
trace("----------------------------");
}
Unfortunately, this is the limitation and will only be able to show you methods with public accessors. You can look at the output of
print data.toXMLString()
as well, to see what else is available for viewing.
精彩评论