# Dynamic function calls in AS 2.0

**URL:** <https://forum.kirupa.com/t/dynamic-function-calls-in-as-2-0/264316>\
**Category:** Uncategorized\
**Created:** [June 24, 2008, 10:46pm UTC](https://forum.kirupa.com/t/dynamic-function-calls-in-as-2-0/264316 "2008-06-24T22:46:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BetaWar](https://avatars.discourse-cdn.com/v4/letter/b/e79b87/32.png) [@BetaWar](https://forum.kirupa.com/u/BetaWar)\
**Post date:** [June 24, 2008, 10:46pm UTC](https://forum.kirupa.com/t/dynamic-function-calls-in-as-2-0/264316/1 "2008-06-24T22:46:40Z")

</div>

I am not quite sure if this is even possible with Flash, but I have done it successfully in other programming languages.

At this point I have a function that is given 2 parameters (object and func) and am wanting to be able to call the object’s function (func) within the function that I have (as to make things simple and even be able to just loop through an array calling each function as I go (dynmically).

Here is my current function:

```auto
function doFunc(object, event){
  object.event();
}

```

And I am passing it something like so:

```auto
doFunc(test_btn, "doSomething");

```

where test\_btn is a simple button movieclip that has the function doSomething inside of it (like so):

```auto
function doSomething(){
  trace("Function called successfully");
}

```

The only issue here is that it doesn’t seem to work out any way I have tried it. If anyone knows what is going on here (or if this is even possible in AS) I would be really thankful.

Thanks in advance, and hopefully this is allowed…

---

<div class="post-metadata">

**Author:** ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)\
**Post date:** [June 24, 2008, 11:59pm UTC](https://forum.kirupa.com/t/dynamic-function-calls-in-as-2-0/264316/2 "2008-06-24T23:59:46Z")

</div>

It’s possible. Do you need to pass the function name instead of the function? If you just pass _doSomething_ instead of _“doSomething”_, then you can just call _event()_ in _doFunc_.

Is _doSomething_ defined inside (as a property of) _test\_btn_ the syntax that you used implied that it was. If so, you can call the function using a string like so:

```auto
object[event]()

```

If the function is defined on another accessible scope, then you need to target it properly. Most probably, it’s just defined on _this_.

---

<div class="post-metadata">

**Author:** ![BetaWar](https://avatars.discourse-cdn.com/v4/letter/b/e79b87/32.png) [@BetaWar](https://forum.kirupa.com/u/BetaWar)\
**Post date:** [June 25, 2008, 1:08am UTC](https://forum.kirupa.com/t/dynamic-function-calls-in-as-2-0/264316/3 "2008-06-25T01:08:21Z")

</div>

Thanks a ton it works 🙂
