PDA

View Full Version : Multidimensional Arrays


NickMalloy
04-10-2003, 05:43 PM
How do you create a multidimensional array in actionscript? How do you assign elements to it?

bluegel
04-10-2003, 05:55 PM
have you done searches for this??

anyway, basic jist depends on type of size, ie 2D etc.

ok, example from actionscript, the definitive guide:

three rows and two columns (one for quantity and one for price).


var row1 = [6, 2.99]; //quantity 6, price 2.99
var row2 = [3, 3.99]; //quantity 3, price 3.99
var row3 = [1, 18.99]; //quantity 1, price 18.99


place the rows into a container array named spreadsheet in this case:

var spreadsheet = [row1, row2, row3];


and then anything you want to do with those values, you can use loops

If this isn't at all what you want you'll have to excuse me, cos I'm bored and should be going home from work now

NickMalloy
04-10-2003, 06:18 PM
I looked in a couple books I had, and they didn't talk about it. Why do you keep using the var for each row. Is row1 row2, row3 seperate arrays? You can't use

array[1,0] = marcy
array[1,1] = 5.9"

You can't do it like that?

CyanBlue
04-10-2003, 10:47 PM
Howdy...

I don't see anything wrong with bluegel's post regarding var... Her script should be working just fine... ;)

Yes your code should work but you are not really assigning it right...
I have changed the array name to be array1 because 'array' is the reserved word... See how I am using [] as well... Also use quotation marks properly...array1[1][0] = "marcy";
array1[1][1] = 5.9;

littleRichard
04-10-2003, 10:58 PM
well CyanBlue beat me to it, but since i took a minute to wright this here it is anyway...


// a condensed way to write bluegel's example
var spreadsheet = [[6, 2.99], [3, 3.99], [1, 18.99]];

// a quick way to access the data.
for(var c = 0; c < spreadsheet.length; c++)
{
for(var cc = 0; cc < spreadsheet[c].length; cc++)
{
trace("row" + c + ": " + spreadsheet[c][cc])
}
trace("");
}

NickMalloy
04-10-2003, 11:57 PM
thank you for your response. I didn't want to offend anyone. with my question. so if I did CyanBlue I am sorry. I just didn't understand bluegel code. Sorry for any problems

CyanBlue
04-11-2003, 12:04 AM
No... No problem at all and you didn't offend anybody... Right, bluegel??? ;)

As long as you understand what we all have given you, we are all happy... :D

NickMalloy
04-11-2003, 12:43 AM
again I am sorry for any misunderstanding, and you gave me alot and I am grateful for all of your time you have given.

bluegel
04-11-2003, 09:37 AM
no, didn't offend anyone :)