# Creating an Array with Variables

**URL:** <https://forum.kirupa.com/t/creating-an-array-with-variables/10712>\
**Category:** flash\
**Created:** [January 6, 2003, 7:02am UTC](https://forum.kirupa.com/t/creating-an-array-with-variables/10712 "2003-01-06T07:02:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![c\_bass](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@c\_bass](https://forum.kirupa.com/u/c_bass)\
**Post date:** [January 6, 2003, 7:02am UTC](https://forum.kirupa.com/t/creating-an-array-with-variables/10712/1 "2003-01-06T07:02:11Z")

</div>

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.

---

<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:** [January 6, 2003, 11:15am UTC](https://forum.kirupa.com/t/creating-an-array-with-variables/10712/2 "2003-01-06T11:15:15Z")

</div>

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
