• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1407
  • Last Modified:

Declaring a multidimensional associative array in Flash 8 actionscript.

In Flash 8 I need to have a 2-dimensional associative array available to be populated with a variable amount of data coming from my server.  Here is how I have it declared:

line = new Array(new Array(new Array(2)));

To experiment with my definition, I used the following code:

line[0][0].address = "first address";
line[0][0].zip = "first zip";
line[0][1].address = "second address";
line[0][1].zip = "second zip";
line[1][0].address = "third address";
line[1][0].zip = "third zip";

for (i in line){
      for (j in line[i]){
            trace("inside "+j);
            trace("address  = " +line[i][j].address);
            trace("zip = " +line[i][j].zip);

Here is the trace output:

inside 0
address  = first address
zip = first zip

Why is only the first pair of the first line being populated?  Is it possible for me to define this in such a way that I may have a variable number of address/zip pairs for each line as well as a variable number of lines?


1 Solution
I believe you're trying to do something like this:

var line = [];
line[0] = [];
line[0][0] = {}; // object, not array
line[0][0].address = "1st address";
line[0][0].zip = "1st zip";
line[0][1] = {}; // object, not array
line[0][1].address = "2nd address";
line[0][1].zip = "2nd zip";
line[1] = [];
line[1][0] = {}; // object, not array
line[1][0].address = "3rd address";
line[1][0].zip = "3rd zip";
gdejarnettAuthor Commented:
Thanks DiscoNova,
You are right, I was confusing object and arrays.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now