# Dynamic calling of functions with dynamic parameters

**URL:** <https://forum.kirupa.com/t/dynamic-calling-of-functions-with-dynamic-parameters/271028>\
**Category:** Uncategorized\
**Created:** [September 17, 2008, 3:41pm UTC](https://forum.kirupa.com/t/dynamic-calling-of-functions-with-dynamic-parameters/271028 "2008-09-17T15:41:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim\_John](https://avatars.discourse-cdn.com/v4/letter/t/b38774/32.png) [@Tim\_John](https://forum.kirupa.com/u/Tim_John)\
**Post date:** [September 17, 2008, 3:41pm UTC](https://forum.kirupa.com/t/dynamic-calling-of-functions-with-dynamic-parameters/271028/1 "2008-09-17T15:41:21Z")

</div>

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:

```auto

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!
