Calling a function with a variable

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.)


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:


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?