I am not clear what you need, but one thing that can be helpful is, try to keep the function argument with type Function and not String. Keeping with type Function, you can directly run it. Handling a function call with String type won't let you get to the function.
I was perhaps not clear enough in my description.
The object Foo is the one being called through a function.
var myFoo:Foo=new Foo();
the point is that within Foo, there should be the function:
so that you can dynamically assign functions or mutate behaviour at runtime or whatever.
Hope this adds clarity to my question.
I'd be interested to know more about what you are trying to achieve, but the code below should work:
public function handleFunctionCall( functionName : String, args : Array ) : *
var functionToCall : Function = this[ functionName ];
return functionToCall.call( this, args );
For alternative approaches you may want to take a look at behavioural design patterns. The command or strategy pattern may suit your needs.
thanks, but that's not what I'm looking for.
I want object.functionToCall(param1) to execute object.handleFunctionCall
with functionName="functionToCall", args=[param1]
Reading some more, I'm not even sure it's possible in AS3
No I don't think it is.
you sir, are a genius.