PDA

View Full Version : Multidimensional array (Flash MX)



silverType
March 13th, 2003, 10:25 AM
Hi guys,
I have created a 2 dimensional array call table and want to assign each and every elements in that array to 0. The codes below shows how I have done it:

var table = new Array();

table = [ [0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0] ];

Just like to find out if there is a simpler way to do it. I've tried doing it with a 'for' loop but I always get 'undefined' values.

So, anyone has got any idea on how to do it?

RvGaTe
March 13th, 2003, 10:36 AM
this one works:



// this one will make an 20x20 array....
// you can change this if you want...
myArray = new Array();
for(i=0;i<20;i++){
myArray[i] = new Array();
for(ii=0;ii<20;ii++){
myArray[i][ii] = 0;
}
}


you need to declare the Array twice with an 2 dem. array (only with using a loop)

jonnooe
March 17th, 2003, 01:29 AM
if i starts at 0 and goes until <= 20 wouldnt that create a 21X21 array because i know it would in c++ and i dont know much about actionscript yet (just trying to find some simarlities here)

CyanBlue
March 17th, 2003, 02:22 AM
I think you are right, jonnooe... ;)

RvGaTe
March 17th, 2003, 04:40 AM
oops :P make that < instead of <= hehe stupid me

silverType
March 17th, 2003, 07:39 AM
LOL...Thanks for your help, guys. Really appreciate it.