Multidimensional arrays in AS3

Here’s a wrapper function that returns a 2d array with simple input. Doing 2d+ arrays in actionscript is a pain, because each Array() constructor only accepts the length for a single dimension. I put this in a static class called ‘Global’ along with other helper functions:

public static function array(xx:int, yy:int):Array
 {
   var newArray:Array = new Array(xx);
   for (var i:int = 0; i < xx; i++) {
     newArray[i] = new Array(yy);
   }
   return newArray;
 }

Later, in-line I can do:

var myArray:array = Global.array(x,y);
Advertisements
This entry was posted in Work. Bookmark the permalink.

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