Defining the Matrix
Defining the Matrix
Wikipedia defines a matrix as “a rectangular table of numbers or, more generally, of elements of a ring-like algebraic structure.” Essentially, a matrix in Flash is exactly that: a table of values made up any number of rows and columns. When discussing the number of rows and columns that a matrix contains, I refer to its dimensions and use the phraseology “number of rows by number of columns.”
The matrix in Figure 1 is referred to as a 3 x 3 matrix (three rows by three columns). Along with understanding matrix dimensions, it is important to understand that each value in a matrix is used to store a piece of data that can be used in a calculation—such as those used in flash.geom.Matrix, flash.filters.ColorMatrixFilter and flash.filters.ConvolutionFilter.
Because Flash does not have a generic matrix class—the class flash.geom.Matrix deals specifically with transformations—it’s necessary to find some way to represent the rows and columns of other types of matrices in Flash. An array can be used for this purpose. The values in the matrix in Figure 1 can be represented by the following array:
[a, b, c, d, e, f, g, h, i]
As you will see, this is often expressed in the following format:
[ a, b, c, d, e, f, g, h, i ]
Flash allows arrays to be declared over multiple lines, so typing it this way provides the added benefit of seeing the number of rows and columns in a matrix, as well as the row and column to which a value corresponds. On its own, of course, it’s still just an array.
However, I will discuss how an array like this (and the concept of matrices as a whole) provides a very granular level of control over things like transformations, gradients, color adjustments, and convolution effects in Flash 8. This article examines each of these matrices and provides practical examples of how they can be relevant in your day-to-day development.
Before we move on to matrix types, it’s important to understand the concept of an identity matrix. This is a matrix that causes no effect when it’s concatenated with another matrix of the same dimensions. Although I won’t discuss the math behind matrix concatenations, suffice it to say it’s important to have an understanding of the term because you will likely encounter it when working in the world of matrices.
Generally speaking, an identity matrix can be represented by a diagonal matrix of 1s starting at the top left (0, 0). All other values in the matrix are 0s. Figure 2 shows a 3 x 3 identity matrix.
The following sections will discuss specific uses for matrices in Flash. You will learn that matrices can provide developers powerful control over Flash movies at the pixel level.