Undolibrary MatrixArray: an extension of class Array
Monday, 15 September, 2008 MatrixArray is an extension of class Array of Actionscript 3.0, with the aim to simplify the handling of Array used as a linear array n x m. This class is part of the library Undolibrary (in the package undolibrary.utils.MatrixArray that you can freely from the download Google code through any client SVN (Subversion) at:
svn checkout http://undolibrary.googlecode.com/svn/trunk/
Or you can just download the file MatrixArray.as. An example of the use of linear arrays has been given in Actionscript 3.0 for beginners: lesson # 2 where we saw a simple use in the implementation of the classic game Tic Tac Toe. A matrix of this type is comparable to a rectangular area w x h just like a chessboard. With this class you can treat an array such as a grid with its x and y coordinates. The MatrixArray I used, for example, development of the whole logic of the editor Emotions Icons for Skype: Skypemote.
Methods
The class MatrixArray therefore extends the normal class Array adding a number of useful ways to manage and manipulate m x n matrix. To create a matrix n x m is enough to use:
- / / Importanzione class - if you downloaded the entire library Undolibrary
- / / Alternatively you can just download the file and use it MatrixArray.as alone
- . MatrixArray ; import undolibrary. utils. MatrixArray;
- / /
- MatrixArray ( 10 , 10 ) ; var but: MatrixArray = new MatrixArray (10, 10);
Created the 10x10 matrix, as in the previous example, we can manipulate it with useful methods that make our work very rapidly and easily. In fact, the 10x10 matrix is nothing more than a simple linear array of 100 items!
clip ()
- / **
- * Restitusice a rectangular portion of the matrix in the form MatrixArray
- *
- * @ Param (UINT) left coordinates x cutting
- * @ Param (UINT) sy y coordinates of the cut
- * @ Param (UINT) cw horizontal size of the cut
- * @ Param (UINT) ch vertical size of the cut
- * @ Result (MatrixArray) A new matrix x cw ch
- *
- * /
- :MatrixArray clip (left: UINT, sy: UINT, cw: UINT, ch: UINT): MatrixArray
- / / Example
- / / Create a new MatrixArray coordinates 2,2 and large and high-5
- ( 2 , 2 , 5 , 5 ) ; var NMa: MatrixArray = ma. clip (2, 2, 5, 5);
fill ()
- / **
- * Fill the array with a value
- *
- * @ Param (any) value to be included in the matrix
- * /
- ; fill (v *);
paintChar ()
- / **
- * Fill the array with one (only) a sample from a string
- * Length equal to the size of the matrix itself
- *
- * @ Param (string) v string with the number of characters to map
- * @ Result (boolean) ok true, false error: string length wrong
- *
- * /
- ) paintChar (v: string)
- / / Example
- MatrixArray ( 10 , 5 ) ; var but: MatrixArray = new MatrixArray (10, 5);
- ma. paintChar (
- '**********' +
- '**##**##**' +
- '**********' +
- '**#####**' +
- '**********'
- );
flipH (), flipV ()
- / **
- * Performs a reflection orizziontale (flipH) or
- * Vertical (flipV) directly on the matrix
- * /
- flipH (): void
- flipV (): void
move ()
- / **
- * Move the contents of the matrix (running a shift) in the four
- * Direction of a predetermined offeset
- * /
- , oy: int ) : void move (ox: int, oy: int): void
- / /
- MatrixArray ( 10 , 5 ) ; var but: MatrixArray = new MatrixArray (10, 5);
- ma. paintChar (
- '**********' +
- '**##**##**' +
- '**********' +
- '**#####**' +
- '**********'
- );
- 2 , 4 ) ; ma. move (2, 4);
- / / Output
- **** ##**##
- **********
- **** #####
- **********
- **********
peek ()
- / **
- * Returns the contents of the grid coordinates x, y
- * /
- :* peek (x: UINT, y: UINT): *
poke ()
- / **
- * Sets the contents of the grid coordinates x, y
- * /
- : void poke (x: UINT, y: UINT): void
getString ()
- / **
- * Used for debugging often returns the matrix as a string nxm
- * /
- getString (): String


















Leave a comment