Chris R
Chris R

Reputation: 17916

How can I determine a function's argument count at runtime in Flex 3?

I want to pass an optional data parameter to some callbacks, but only to callbacks that support a single parameter; right now, I have a moderately-sized code base of callbacks that cannot accept a parameter at all. How can I check what parameters a Function object supports?

Upvotes: 12

Views: 2207

Answers (3)

Lex
Lex

Reputation: 1378

Function is an Object. Every function has a read-only property named length that stores the number of parameters defined for the function. Use it.

Upvotes: 20

Robusto
Robusto

Reputation: 31883

The arguments array is an array of all the parameters passed into a function. Maybe that is what you are looking for?

function traceArgArray(x:int):void
{
    for (var i:uint = 0; i < arguments.length; i++)
    {
        trace(arguments[i]);
    }
}

Example taken from livedocs.adobe.com

Upvotes: 1

Patrick
Patrick

Reputation: 15717

If your function is declared in a class use the function describeType it will return an XML you can parse and look at your function name with his arguments

Upvotes: 2

Related Questions