Creating an Array with Variables

Is it possible to create an array based on a list of items stored in a variable?

Heres an example:

This is my list of items stored in a variable…

MENU_BUTTONS = “home”, “about LRD”, “members”, “games”, “downloads”, “links”;

I then initalize my array with the attempt to assign the contents of the array with my items stored in my MENU_BUTTONS variable…

BUTTONS = new Array(MENU_BUTTONS);

This does not work. It only assigns BUTTONS[0] with the value “home” and nothing else.

On the other hand, this does work.

BUTTONS = new Array(“home”, “about LRD”, “members”, “games”, “downloads”, “links”);

I would not think that Flash would know the difference between the two different sets of code because the MENU_BUTTONS variable is just a reference to my list of items.

You’re probably wondering why I just dont stick with the second approach which works fine. But I am planning on loading the MENU_BUTTONS variable from a text file in the final version of the program.

Thanks for your time.

Hi,

Is it possible to create an array based on a list of items stored in a variable?

A variable that stores a list of items** is an array!** and it’s syntax is
MENU_BUTTONS = [“home”, “about LRD”, “members”, “games”, “downloads”, “links”];

If you want to load those values from a text file you should load them one by one and push them into the array (unless you load an object with a MENU_BUTTONS property containing the array, I’m making a guess here). In this case you should initialize the array:
MENU_BUTTONS = new Array();
and then push the values into it:
MENU_BUTTONS.push(“home”);

MENU_BUTTONS.push(“links”); //well u push the variable name with this value.
And so on.

Hope it helps

Cheers

SHO