# Calling a function with a variable

**URL:** <https://forum.kirupa.com/t/calling-a-function-with-a-variable/191955>\
**Category:** Uncategorized\
**Created:** [June 24, 2006, 10:44am UTC](https://forum.kirupa.com/t/calling-a-function-with-a-variable/191955 "2006-06-24T10:44:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dal\_platinum](https://avatars.discourse-cdn.com/v4/letter/d/ed8c4c/32.png) [@dal\_platinum](https://forum.kirupa.com/u/dal_platinum)\
**Post date:** [June 24, 2006, 10:44am UTC](https://forum.kirupa.com/t/calling-a-function-with-a-variable/191955/1 "2006-06-24T10:44:05Z")

</div>

I’m just getting the hang of AS2 OOP, after avoiding it for all this time, and I have set up my first couple of classes.

One class generates an array, and the other class takes this array, and uses it it to place MC’s on the screen, and gives each mc an onEnterFrame function. I have a stack of these onEnterFrame functions, named ‘avoidIt1()-avoidIt11()’

I want to choose the function randomly, at runtime. Is this possible?

here is a snippet of code from it: (I can’t attach the whole thing, I’m at work, and I left a rather major section of the code at home.)

```auto

this.createEmptyMovieClip("block"+n,200+n);
var tt:MovieClip = this["block"+n];
if (targetarray[row][col]){
    tt.beginFill(cl1);
} else {
    //delete tt;
    tt.beginFill(cl2);
}
tt.moveTo(-50,-50);
tt.lineTo(50,-50);
tt.lineTo(50,50);
tt.lineTo(-50,50);
tt.endFill();
tt._xscale = bsize;
tt._yscale = bsize;
tt.myscale = bsize;
tt._x = ax + gap*col;
tt._y = ay + gap*row;
tt.homeX = ax + gap*col;
tt.homeY = ay + gap*row;
tt.avoidIt8(); // this is where I need to bring in a random function
n++

```

I tried:

```auto

tt["avoidIt"+rnd_number+"()"];

```

But I guess that’s just for referencing objects.

I’m sure it’s just a syntax thing I haven’t seen before, but I’m having the devil’s own job trying to find out what it is.

Either that, or I’m going about this the wrong way.

Another solution I had was to use a great long CASE list, but this seems a bit messy.

Anyone have any ideas?
