If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Arrays and Functions

I have an array which contains the names of functions (a1() and a2()) and
a function is randomly picked. My problem is that the function name is stored
in a variable (choosescript) and I cannot work out how to run the function.
Here is the script:

Re: Arrays and Functions

if (choosescript.equals("a1")) a1();
if (choosescript.equals("a2")) a2();

There are other ways to do this, but they would require more changes.

PC2

Matt <matt0220@aol.com> wrote in message news:39ccdeac$1@news.devx.com...
>
> I have an array which contains the names of functions (a1() and a2()) and
> a function is randomly picked. My problem is that the function name is
stored
> in a variable (choosescript) and I cannot work out how to run the
function.
> Here is the script:
>
> function mine() {
> var scriptlist = new Array;
> var choosescript;
> scriptlist[0] = "a1"
> scriptlist[1] = "a2"
> choosescript = scriptlist[Math.floor(Math.random() * scriptlist.length)];
>
> Any ideas please?
>
> Matt (Matt0220@AOL.com)