Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 424

Programming actionscript 3.0
Table of Contents

Advertisement

Defining Matrix objects
Although you could define a matrix by directly adjusting the properties (
,
,
,
,
,
) of a
a
b
c
d
tx
ty
Matrix object, it is easier to use the
method. This method includes parameters
createBox()
that let you directly define the scaling, rotation, and translation effects of the resulting matrix.
For example, the following code creates a Matrix object that has the effect of scaling an object
horizontally by 2.0, scaling it vertically by 3.0, rotating it by 45 degrees, moving (translating)
it 10 pixels to the right, and moving it 20 pixels down:
var matrix:Matrix = new Matrix();
var scaleX:Number = 2.0;
var scaleY:Number = 3.0;
var rotation:Number = 2 * Math.PI * (45 / 360);
var tx:Number = 10;
var ty:Number = 20;
matrix.createBox(scaleX, scaleY, rotation, tx, ty);
You can also adjust the scaling, rotation, and translation effects of a Matrix object by using the
,
, and
methods. Note that these methods combine with the
scale()
rotate()
translate()
values of the existing Matrix object. For instance, the following code sets a Matrix object that
scales an object by a factor of 4 and rotates it 60 degrees, since the
and
scale()
rotate()
methods are called twice:
var matrix:Matrix = new Matrix();
var rotation:Number = 2 * Math.PI * (30 / 360); // 30°
var scaleFactor:Number = 2;
matrix.scale(scaleFactor, scaleFactor);
matrix.rotate(rotation);
matrix.scale(scaleX, scaleY);
matrix.rotate(rotation);
myDisplayObject.transform.matrix = matrix;
To apply a skew transformation to a Matrix object, adjust its
or
property. Adjusting the
b
c
b
property skews the matrix vertically, and adjusting the
property skews the matrix
c
horizontally. The following code skews the
Matrix object vertically by a factor of 2:
myMatrix
var skewMatrix:Matrix = new Matrix();
skewMatrix.b = Math.tan(2);
myMatrix.concat(skewMatrix);
You can apply a Matrix transformation to the
property of a display object. For
transform
example, the following code applies a matrix transformation to a display object named
:
myDisplayObject
var matrix:Matrix = myDisplayObject.transform.matrix;
var scaleFactor:Number = 2;
var rotation:Number = 2 * Math.PI * (60 / 360); // 60°
matrix.scale(scaleFactor, scaleFactor);
424
Working with Geometry

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents