m X n Arrays in Actionscript 3

Posted: June 22, 2009 in Actionscript
Tags: , , ,

Unlike C and java where u can declare an m x n array simply by writing arr[m][n], its a bit difficult in actionscrpit3.
It was like u have to make an array of arrays:

new Array(new Array(),new Array(),…)

But a little bit effort can find a way out of this mess. You may make use of the following snippet:

function arrayTest(){

var m:int = 2;
var n:int = 2;
var mainArr:Array = new Array(m);
var i:int;
var j:int;
for (i = 0; i < m; i++) {

mainArr[i] = new Array(n);
for (j = 0; j < n; j++) {

mainArr[i][j] = “[” + i + “][” + j + “]”;

}

}
trace(mainArr);

}

It is a bit of a mess but it will work for sure..

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s