Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2-D Array? Is it possible? 2

Status
Not open for further replies.

munkygomoo

Programmer
May 16, 2002
15
US
Is there a way in Flash to create a 2-d array (also known as a matrix)? - JGD -
 
I don't know actionScrip that much but it might be possible to do an array of arrays thus a matrix.

try this in Flash

var myMatrix = [ [1,2,3,4], [5,6,7,8] ];

Before I continue what is that thing in flash you use to display debug info? is it dump()?? I forget! :( Gary Haran
 
Regards,

oldman3.gif
 
this is an example of a 2D array definition matrix (4 by 4):-

var Answer = new Array(new Array(1,0,0,0),new Array(0,0,0,1),new Array(1,0,0,0),new Array(0,0,0,1));
 
Here is a simple way to loop through an associative multidimensional array :


var numbers = [ [11, 22, 33, 44] ,[22, 564, 987, 456], [3], [4, 8] ];
for (var index = 0; index < numbers.length; index++)
{
for (var innerIndex = 0; innerIndex < numbers[index].length; innerIndex++)
{
trace(&quot;<br> at [index][innerIndex] : [&quot; + index + &quot;][&quot; + innerIndex + &quot;]the value is &quot; + numbers[index][innerIndex])
}
}

at [index][innerIndex] : [0][0]the value is 11
at [index][innerIndex] : [0][1]the value is 22
at [index][innerIndex] : [0][2]the value is 33
at [index][innerIndex] : [0][3]the value is 44
at [index][innerIndex] : [1][0]the value is 22
at [index][innerIndex] : [1][1]the value is 564
at [index][innerIndex] : [1][2]the value is 987
at [index][innerIndex] : [1][3]the value is 456
at [index][innerIndex] : [2][0]the value is 3
at [index][innerIndex] : [3][0]the value is 4
at [index][innerIndex] : [3][1]the value is 8

I can't test it cause I don't have dw. Gary Haran
 
Hello,
It is possible to create 2 dimentional array or array of arrays in flash.
One method is to create a one-dimentional array in a variable and then create another array with the different arrays you have created. This will serve the purpose...
While retrieving values, you have to take the one dimentional arrays out and get the values from these 1 D arrays using two 'for' loops, as usual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top