# Variables and arrays

**URL:** <https://forum.kirupa.com/t/variables-and-arrays/17490>\
**Category:** Uncategorized\
**Created:** [April 5, 2003, 10:02pm UTC](https://forum.kirupa.com/t/variables-and-arrays/17490 "2003-04-05T22:02:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hbrouwer](https://avatars.discourse-cdn.com/v4/letter/h/7993a0/32.png) [@hbrouwer](https://forum.kirupa.com/u/hbrouwer)\
**Post date:** [April 5, 2003, 10:02pm UTC](https://forum.kirupa.com/t/variables-and-arrays/17490/1 "2003-04-05T22:02:41Z")

</div>

I’ve written the following script (print from the movie explorer) but I can’t see the inputed variables in the trace screen. What do I do wrong?

greetings,  
Han

Scene 1  
actions for frame 1  
alleWerkgevers = new Array();  
nummer = 1;  
function voegToe(bedrijfsnaam, functie, startDatum, eindDatum, plaats, werkzaamheden){  
\_root[“werkgever”+nummer] = new Array ();  
\_root[“werkgever”+nummer].push(bedrijfsnaam, functie, startDatum, eindDatum, plaats, werkzaamheden);  
alleWerkgevers.push(\_root[“werkgever”+nummer]);  
trace ("werkgever "+nummer + \_root[“werkgever”+nummer]);  
trace ("Alle werkgevers " + alleWerkgevers);  
nummer++;  
}  
function verwijder (){  
alleWerkgevers.pop();  
nummer–;  
trace ("Alle werkgevers "+alleWerkgevers);  
}

(empty), (bedrijfsnaam)  
(empty), (functie)  
(empty), (startDatum)  
(empty), (eindDatum)  
(empty), (plaats)  
(empty), (werkzaamheden)

voegtoeBT, \<voegtoeBT\>  
actions for voegtoeBT  
on (release){  
\_root.voegToe(bedrijfsnaam, functie, startDatum, eindDatum, plaats, werkzaamheden);  
}

verwijderBT, \<verwijderBT\>  
actions for verwijderBT  
on (release){  
\_root.verwijder();  
}

Symbol Definition(s)  
voegtoeBT  
Voeg toe, (Arial, 28 pts)

verwijderBT  
Verwijder, (Arial, 28 pts)

---

<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:** [April 6, 2003, 9:01pm UTC](https://forum.kirupa.com/t/variables-and-arrays/17490/2 "2003-04-06T21:01:07Z")

</div>

!!! JUST GOT BACK INTO FLASH AND I DON’T REMEMBER IF THIS IS CORRECT, SO DON’T KUNG FU MY \*\*\* IF I’M WRONG !!!

I think your problem is here:

\_root[“werkgever”+nummer] = new Array ();

-Im not sure if you can use \_root as an array name, you should try something like this:

arrayName = new Array();

and i don’t think you can have anything other than an number when you call out a part of the array:

someVariable = arrayName[0]

instead of:

someVariable = arrayName[someWord]

---

<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:** [April 6, 2003, 10:14pm UTC](https://forum.kirupa.com/t/variables-and-arrays/17490/3 "2003-04-06T22:14:14Z")

</div>

> \*Originally posted by nemoBejingler \*  
> \*\*I think your problem is here:

\_root[“werkgever”+nummer] = new Array ();

\*\*  
if werkgever is a string try

eval(“\_root.werkgever”+nummer) = new Array()

if werkgever is a variabe try

eval(\_root.werkgever+nummer) = new Array()

> \*Originally posted by nemoBejingler \*  
> \*\*and i don’t think you can have anything other than an number when you call out a part of the array:

someVariable = arrayName[0]

instead of:

someVariable = arrayName[someWord]\*\*

Since you have a numerically indexed array - constructed using push() then you can only use numerical indices. If you want to create an associative array then you would construct it using the syntax

lunchbox=new Array()  
lunchbox[“sandwich”]=“ham and cheese”  
lunchbox[“drink”]=“milk”

if you trace lunchbox[“sandwich”], it will return “ham and cheese”

If you want to create a multi-dimensional array then use the syntax

lunchbox=new Array()  
lunchbox[“sandwich”]=[“bread”, “ham”, “cheese”]

if you trace lunchbox[“sandwich”][1] it will return “ham”

---

<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:** [April 7, 2003, 5:42am UTC](https://forum.kirupa.com/t/variables-and-arrays/17490/4 "2003-04-07T05:42:18Z")

</div>

Thank you for the aswers. I found the problem. It is a silly problem. I explain: I used a MC as a button. In that case you have to write \_root. in front of each variable in the on(release)-function in the MC.  
When you change the MC into an BT then it works without that \_root.  
Very silly!

greetings,  
Han
