# \[CS3/AS2\] How to change values of variables inside the array?

**URL:** <https://forum.kirupa.com/t/cs3-as2-how-to-change-values-of-variables-inside-the-array/284597>\
**Category:** flash\
**Created:** [March 20, 2009, 4:41pm UTC](https://forum.kirupa.com/t/cs3-as2-how-to-change-values-of-variables-inside-the-array/284597 "2009-03-20T16:41:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![descalabro](https://avatars.discourse-cdn.com/v4/letter/d/c6cbf5/32.png) [@descalabro](https://forum.kirupa.com/u/descalabro)\
**Post date:** [March 20, 2009, 4:41pm UTC](https://forum.kirupa.com/t/cs3-as2-how-to-change-values-of-variables-inside-the-array/284597/1 "2009-03-20T16:41:17Z")

</div>

Hi.  
My intention is to have an array with several variables, each one with a different name, all of them of the type ‘Number’. This I can do.

What I can’t do is to access the variables using the array’s index.

Let me exemplify:

Paste this on your frame 1:

```auto

trace("======at frame 1======");
//objects//
var objects:Array = new Array();
objects[0] = carroobj=1;
objects[1] = crapobj=2;
objects[2] = tractorobj=3;
objects[3] = truckobj=1;
objects[4] = hammerobj=1;
objects[5] = keyobj=1;
trace("carroobj "+carroobj);
trace("array objects "+objects);
//object frames//
var objectsframe:Array = new Array();
objectsframe[0] = carroobjframe=43;
objectsframe[1] = crapobjframe=14;
objectsframe[2] = tractorobjframe=18;
objectsframe[3] = truckobjframe=3;
objectsframe[4] = hammerobjframe=45;
objectsframe[5] = keyobjframe=70;
trace("array objectsframe "+objectsframe);
trace("carroobjframe "+carroobjframe);

```

Paste this on your frame 3:

```auto

stop();
trace("======at frame 3======");
for (i=0; i<objects.length; i++) {
 trace("array element from objects "+objects*);
 if (objects* == 1) {
  objectsframe* = _root._currentframe;
  trace("array element from objectsframe "+objectsframe*);
 }
}
trace("array objectsframe "+objectsframe);
trace("carroobjframe "+carroobjframe);

```

The result will be:

```auto

======at frame 1======
carroobj 1
array objects 1,2,3,1,1,1
array objectsframe 43,14,18,3,45,70
carroobjframe 43
======at frame 3======
array element from objects 1
array element from objectsframe 3
array element from objects 2
array element from objects 3
array element from objects 1
array element from objectsframe 3
array element from objects 1
array element from objectsframe 3
array element from objects 1
array element from objectsframe 3
array objectsframe 3,14,18,3,3,3
carroobjframe 43

```

As you can see, the code is changing the value of the array element and not the value of the variable inside the array element.

I know my code is wrong, but how do I access and change the value of variables inside the array using the array’s index?

Thsnk you for any help.
