# Calling a function with a variable

**URL:** <https://forum.kirupa.com/t/calling-a-function-with-a-variable/6410>\
**Category:** flash\
**Created:** [October 6, 2002, 10:15pm UTC](https://forum.kirupa.com/t/calling-a-function-with-a-variable/6410 "2002-10-06T22:15:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![GuZ](https://avatars.discourse-cdn.com/v4/letter/g/41988e/32.png) [@GuZ](https://forum.kirupa.com/u/GuZ)\
**Post date:** [October 6, 2002, 10:15pm UTC](https://forum.kirupa.com/t/calling-a-function-with-a-variable/6410/1 "2002-10-06T22:15:36Z")

</div>

hi,

ny1 got a clue how to call a function with a variable in the name?

e.g.:

function CallMyFunction (cmd) {  
eval(cmd);  
}  
CallMyFunction(“trace(“Hey!”);”);

this doesnt work; but perhaps someone knows how to get this to work.  
GuZ

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 6, 2002, 10:21pm UTC](https://forum.kirupa.com/t/calling-a-function-with-a-variable/6410/2 "2002-10-06T22:21:06Z")

</div>

```auto
function myFunc(a){
  a=a+5;
}
trace (myFunc(5));
// returns 10

```

Is that what you wanted to know:q:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 6, 2002, 11:01pm UTC](https://forum.kirupa.com/t/calling-a-function-with-a-variable/6410/3 "2002-10-06T23:01:37Z")

</div>

nope sorry,

i want to make a function that can run any function with a variable:  
e.g.:

cmd=“trace(1);”;  
eval(cmd);

should result: 1

only it doesnt work.  
i need this to make a single function for a timer; so i want to run several functions after a delay, using setInterval(); only the funciton must be runned once, and using setInterval would cause a loop; so i want to use setinterval with a variable to a simple script that runs the variable command, and then clears the interval.

> \*Originally posted by ilyaslamasse \*  
> \*\*

```auto
function myFunc(a){
  a=a+5;
}
trace (myFunc(5));
// returns 10

```

Is that what you wanted to know:q: \*\*
