Max
Max

Reputation: 8045

how to get a function's info in actionscript?

i often get argument mismatch error ,that usually take me a lot of time to debug program.damn, i really hope i know the function's entrance requirement and where they are come from.

since i only know a function variable is a function,no any other information. i wrote massive codes like this

    public static function call(func:Function,params:Array = null,addToTailIfNotNull:*=null):void{
        if (func!=null){
            var args:Array =[];
            if(params!=null){
                args = ArrayTools.clone(params); 
            }
            if (addToTailIfNotNull!=null){
                args.push(addToTailIfNotNull);
            }
            func.apply(null,args);
        }
    }

i should do things more smartly .

Upvotes: 0

Views: 93

Answers (1)

Max Golovanchuk
Max Golovanchuk

Reputation: 747

I can suggest you using flash.utils.describeType() method. It returns an XML with a description of an object you passed as a parameter.

Lets say you have a Class:

public class Example {
    public function someMethod(number:Number, string:String):void {

    }
}

And you call somewhere:

flash.utils.describeType(Example);

You should get an XML with something like this in there:

<method name="someMethod" declaredBy="com.example::Example" 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="501"/>
  </metadata>
</method>

I am not sure that this is what you looking for, as in your example if you pass you Function argument there you will get a description of Function class:

<type name="builtin.as$0::MethodClosure" base="Function" isDynamic="false" isFinal="true" isStatic="false">
  <extendsClass type="Function"/>
  <extendsClass type="Object"/>
  <accessor name="length" access="readonly" type="int" declaredBy="Function"/>
  <accessor name="prototype" access="readwrite" type="*" declaredBy="builtin.as$0::MethodClosure"/>
</type>

But maybe you can refactor you "call" method so it could get the right description (for example pass additional info into it - like an object class and a method name - so you could analyse the method signature in it. Not the most beautiful solution, but still...)

Upvotes: 2

Related Questions