13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Working with geometry<br />

Defining the MatrixTransformer class<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

The MatrixTransformer class includes static methods that apply geometric transformations of Matrix objects.<br />

The transform() method<br />

The transform() method includes parameters for each of the following:<br />

sourceMatrix—The input matrix, which the method transforms<br />

xScale and yScale—The x and y scale factor<br />

dx and dy—The x and y translation amounts, in pixels<br />

rotation—The rotation amount, in degrees<br />

skew—The skew factor, as a perc<strong>en</strong>tage<br />

skewType—The direction in which the skew, either "right" or "left"<br />

The return value is the resulting matrix.<br />

The transform() method calls the following static methods of the class:<br />

skew()<br />

scale()<br />

translate()<br />

rotate()<br />

Each returns the source matrix with the applied transformation.<br />

The skew() method<br />

The skew() method skews the matrix by adjusting the b and c properties of the matrix. An optional parameter, unit,<br />

determines the units used to define the skew angle, and if necessary, the method converts the angle value to radians:<br />

if (unit == "degrees")<br />

{<br />

angle = Math.PI * 2 * angle / 360;<br />

}<br />

if (unit == "gradi<strong>en</strong>ts")<br />

{<br />

angle = Math.PI * 2 * angle / 100;<br />

}<br />

A skewMatrix Matrix object is created and adjusted to apply the skew transformation. Initially, it is the id<strong>en</strong>tity<br />

matrix, as follows:<br />

var skewMatrix:Matrix = new Matrix();<br />

The skewSide parameter determines the side to which the skew is applied. If it is set to "right", the following code<br />

sets the b property of the matrix:<br />

skewMatrix.b = Math.tan(angle);<br />

Otherwise, the bottom side is skewed by adjusting the c property of the Matrix, as follows:<br />

skewMatrix.c = Math.tan(angle);<br />

Last updated 6/6/2012<br />

218

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!