User Guide
Using Matrix objects 425
matrix.rotate(rotation);
myDisplayObject.transform.matrix = matrix;
The first line sets a Matrix object to the existing transformation matrix used by the
myDisplayObject display object (the matrix property of the transformation property of
the
myDisplayObject display object). This way, the Matrix class methods that you call will
have a cumulative effect on the display object’s existing position, scale, and rotation.
Defining a Matrix object for use with a gradient
You use the beginGradientFill() and lineGradientStyle() methods of the
flash.display.Graphics class to define gradients for use in shapes. When you define a gradient,
you supply a matrix as one of the parameters of these methods.
The easiest way to define the matrix is by using the
createGradientBox() method, which
defines a rectangle that is used to define the gradient. You define the scale, rotation, and
position of the gradient by using the parameters passed to the
createGradientBox()
method.
For example, consider a gradient with the following characteristics:
■ GradientType.LINEAR
■ Two colors, green and blue, with the ratios array set to [0, 255]
■ SpreadMethod.PAD
■ InterpolationMethod.LINEAR_RGB
NOTE
The ColorTransform class is also included in the flash.geometry package. This class
is used to set the colorTransform property of a Transform object. Since it does not
apply any sort of geometrical transformation, it is not discussed in this chapter. For
more information, see the ColorTransform class in the ActionScript 3.0 Language
Reference.