Declaring a multidimensional associative array in Flash 8 actionscript.

Posted on 2007-10-10
Last Modified: 2008-01-09
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?


Question by:gdejarnett
    LVL 7

    Accepted 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";

    Author Comment

    Thanks DiscoNova,
    You are right, I was confusing object and arrays.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    Accessibility and Usability are two concepts that seem to be closely related.  But, too many people seem to have a distorted perception of them. During last five years, those two words have come to the day-to-day work of almost every web develope…
    The goal of the tutorial is to teach the user how to how to record live broadcast.
    The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now