# Two Dimensional Arrays

**URL:** <https://forum.kirupa.com/t/two-dimensional-arrays/57333>\
**Category:** flash\
**Created:** [July 12, 2004, 1:30pm UTC](https://forum.kirupa.com/t/two-dimensional-arrays/57333 "2004-07-12T13:30:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Relain](https://avatars.discourse-cdn.com/v4/letter/r/aca169/32.png) [@Relain](https://forum.kirupa.com/u/Relain)\
**Post date:** [July 12, 2004, 1:30pm UTC](https://forum.kirupa.com/t/two-dimensional-arrays/57333/1 "2004-07-12T13:30:28Z")

</div>

Well, first of all Hello Everyone.

I’ve been trying to use ActionScript to create an isometric pseudo3d terrain generator thing, using a dot movie clip.

I come from a C programming background and i thought it’d be pretty easy to just attach a load of movie clips to the stage and put them all (well references to them) into a 2d array so i could call back to them with ease for the moving and the jiggery pokery.

This is what i think sets up a 2d array called point\_set, pretty strange syntax a mon avis…

point\_set = new Array;  
point\_set = [[],[]];

Then i attach the movie clips using some nested for loops:

vertex = attachMovie(“mcPoint”, “n”+total, total);  
point\_set[j]\* = vertex;

Then when i try and actually reference them, in this fashion:

onEnterFrame = function()  
{  
for (j=0; j\<height; j++)  
{  
for (i=0; i\<width; i++)  
{  
node = point\_set[j]\*;  
// rest of the function…

but i only get a few of the points in the onEnterFrame. Viz:

[www.relain.co.uk/stuff/flash/landscape.fla](http://www.relain.co.uk/stuff/flash/landscape.fla)

and actually at:

[www.relain.co.uk/stuff/flash/landscape.swf](http://www.relain.co.uk/stuff/flash/landscape.swf)

[it is actually an isometric grid, well on a Pi/6 angle but its not set up yet]

Well thanks a lot for any help folks

---

<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:** [July 12, 2004, 7:51pm UTC](https://forum.kirupa.com/t/two-dimensional-arrays/57333/2 "2004-07-12T19:51:35Z")

</div>

Unexpected file format. Can you save as Flash MX?

---

<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:** [July 12, 2004, 8:03pm UTC](https://forum.kirupa.com/t/two-dimensional-arrays/57333/3 "2004-07-12T20:03:28Z")

</div>

some of the fla code was a little different… you were using point\_set[[j], \*] in some places which is incorrect.

In Flash, a 2D array is basically just a basic array of arrays (nothing fundamentally unique as a structure). So your first dimension in the array, your j collection of indices is the main array whos elements are all arrays to hold your values. This means that for each iteration of j in your 2d array creation/assignment, you need to create a new array at that index. From there, you can then add values to that interior array’s indices making up the elements of the full 2d array.

```auto
point_set = new Array(); // all you need to start
for (j=0; j<height; j++){
     point_set[j] = new Array(); // adding your second dimension - needed for each j
     for (i=0; i<width; i++){
          point_set[j]* = value; // point_set[j] is now an array and an i element can be accessed via array access brackets []
     }
}

```
