Article View: adobe.livemotion.actionscript
Article #7Re: multi-dimensional arrays
From: Bo_Hjort_Nielsen
Date: Tue, 31 Aug 2004 20:40
Date: Tue, 31 Aug 2004 20:40
106 lines
1934 bytes
1934 bytes
If you have a short multi dimensional array, you could simply type it out...like this (indented for clarity)
_root.DirectorArray =
[
["dir_1", "D_1"],
["dir_2", "D_2"],
["dir_3", "D_3"],
["dir_4", "D_4"]
];
now
_root.DirectorArray[2][0];
would return
"dir_3"
But if the content of your array is fairly large and as structured as your example imply, you might safe some typing and perhaps gain some flexibility by using a series of anonymous objects in a "regular" array for ease of access?
_root.DirectorArray = new Array ();
var maxNum = 20; // number of objects in array
for (i=0; i<maxNum; i++) {
var temp = new Object();
temp.mcName = "dir_" + i;
temp.mcLabel = "D_" + i;
_root.DirectorArray.push(temp)
}
Now
_root.DirectoryArray[3].mcName;
would return
"dir_3"
and similar
_root.DirectoryArray[3].mcLabel;
would return
"D_3"
I haven't actually tested any of this, so no guarantees it will work exactly as typed here. Let me know if I messed it up somewhere.
Hope it helps...
-Bo
Technical Details
Message-ID:
<3bb5b305.1@webx.la2eafNXanI>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!news.zanker.org!npeer.de.kpn-eurorings.net!feed.news.schlund.de!schlund.de!newsfeed01.sul.t-online.de!t-online.de!webxReferences:
<3bb5b305.-1@webx.la2eafNXanI>Show Full Headers
Complete Article Headers
X-Google-Thread: f81fe,76cc1e67d1b3481 X-Google-Attributes: gidf81fe,public X-Google-Language: ENGLISH,ASCII-7-bit From: Bo_Hjort_Nielsen@adobeforums.com Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!news.zanker.org!npeer.de.kpn-eurorings.net!feed.news.schlund.de!schlund.de!newsfeed01.sul.t-online.de!t-online.de!webx Newsgroups: adobe.livemotion.actionscript Subject: Re: multi-dimensional arrays Message-ID: <3bb5b305.1@webx.la2eafNXanI> Date: Tue, 31 Aug 2004 13:40:36 -0700 References: <3bb5b305.-1@webx.la2eafNXanI> Lines: 62 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit