Fragsworth Fragsworth - 1 year ago 132
ActionScript Question

How to retrieve a function or method's argument / parameter list from outside the function in Actionscript 3

In another class elsewhere in the code, I want to access the parameters (and their types) of
The result would contain
[ "a", Number ]
[ "b", String ]
in one form or another.

public class Foo
public function bar(a:Number, b:String):void

Answer Source

AS3 has a method called describeType

If you call describeType(Foo) on the above example, you'll get:

<type name="Foo" base="Class" isDynamic="true" isFinal="true" isStatic="true">
  <extendsClass type="Class"/>
  <extendsClass type="Object"/>
  <accessor name="prototype" access="readonly" type="*" declaredBy="Class"/>
  <factory type="Foo">
    <extendsClass type="Object"/>
    <method name="bar" declaredBy="Foo" returnType="void">
      <parameter index="1" type="Number" optional="false"/>
      <parameter index="2" type="String" optional="false"/>
      <metadata name="__go_to_definition_help">
        <arg key="pos" value="51"/>
    <metadata name="__go_to_definition_help">
      <arg key="pos" value="23"/>

Now, you can use AS3's XML class and e4x to find the definition of the method with the name bar and grab the parameter elements.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download