Hello all,
I’m pulling info from an XML file. The info corresponds to the properties of buttons that will each have a different behaviour. First of all I wanted to specify in my XML the name of the function to run when the button is pressed. Previously I understand that there was a function called eval() or exec() that would run a string as if it were code. But not any more. It turns out you can do it with dynamic referencing, like this:
function traceIt():void
{
[INDENT]trace("It");[/INDENT]
}
var funcName:String = "traceIt";
this[funcName]();
Great!
Now the problem is to do with the number of parameters that different functions accept. Say one of the functions required no parameters, and another required 2 - how could I deal with both these situations dynamically? Ok, sure I can put load of if statements in up to a maximum number of parameters, but that’s hacky.
Is there a way for example of calling a function using a special kind of array that will map out to the parameters required by a given function? Yeah it’s a long shot, but AS3 has had quite a few tricks up its sleeve that have pleasantly surprised me in the past!
Cheers guys!