View comments | RSS feed

Matrix (flash.geom.Matrix)


Object
    |
    +-flash.geom.Matrix

public class Matrix
extends Object

The flash.geom.Matrix class represents a transformation matrix that determines how to map points from one coordinate space to another. By setting the properties of a Matrix object and applying it to a MovieClip or BitmapData object you can perform various graphical transformations on the object. These transformation functions include translation (x and y repositioning), rotation, scaling, and skewing.

Together these types of transformations are knows as affine transformations. Affine transformations preserve the straightness of lines while transforming, and parallel lines stay parallel.

To apply a transformation matrix to a movie clip, you create a flash.geom.Transform object, and set its Matrix property to the transformation matrix. Matrix objects are also used as parameters of some methods, such as the draw() method of the flash.display.BitmapData class.

A transformation matrix object is considered a 3 x 3 matrix with the following contents:



In traditional transformation matrixes the u, v, and w properties provide extra capabilities. The Matrix class can only operate in two-dimensional space so it always assumes that the property values u and v are 0.0, and that the property value w is 1.0. In other words the effective values of the matrix are as follows:



You can get and set the values of all six of the other properties in a Matrix object: a, b, c, d, tx, and ty.

The Matrix class supports the four major types of transformation functions: translation, scaling, rotation, and skewing. There are specialized methods for three of these functions, as described in the following table.

Transformation

Method

Matrix values

Display result

Description

Translation (displacement)

translate(tx, ty)





Moves the image tx pixels to the right and ty pixels down.

Scaling

scale(sx, sy)





Resizes the image, multiplying the location of each pixel by sx on the x axis and sy on the y axis.

Rotation

rotate(q)





Rotates the image by an angle q, which is measured in radians

Skewing or shearing

None; must set the properties b and c.





Progressively slides the image in a direction parallel to the x or y axis. The value skx acts as a multiplier controlling the sliding distance along the x axis; sky controls the sliding distance along the y axis.

Each transformation function alters the current matrix properties so that you can effectively combine multiple transformations. To do this, you call more than one transformation function before applying the matrix to its movie clip or bitmap target.

Availability: ActionScript 1.0; Flash Player 8

See also

transform (MovieClip.transform property), Transform (flash.geom.Transform), draw (BitmapData.draw method), a (Matrix.a property), b (Matrix.b property), c (Matrix.c property), d (Matrix.d property), tx (Matrix.tx property), ty (Matrix.ty property), translate (Matrix.translate method), scale (Matrix.scale method), rotate (Matrix.rotate method)

Property summary

Modifiers

Property

Description

 

a:Number

The value in the first row and first column of the Matrix object, which affects the positioning of pixels along the x axis when scaling or rotating an image.

 

b:Number

The value in the first row and second column of the Matrix object, which affects the positioning of pixels along the y axis when rotating or skewing an image.

 

c:Number

The value in the second row and first column of the Matrix object, which affects the positioning of pixels along the x axis when rotating or skewing an image.

 

d:Number

The value in the second row and second column of the Matrix object, which affects the positioning of pixels along the y axis when scaling or rotating an image.

 

tx:Number

The distance by which to translate each point along the x axis.

 

ty:Number

The distance by which to translate each point along the y axis.

Properties inherited from class Object

constructor, __proto__, prototype, __resolve


Constructor summary

Signature

Description

Matrix([a:Number], [b:Number], [c:Number], [d:Number], [tx:Number], [ty:Number])

Creates a new Matrix object with the specified parameters.

Method summary

Modifiers

Signature

Description

 

clone() : Matrix

Returns a new Matrix object that is a clone of this matrix, with an exact copy of the contained object.

 

concat(m:Matrix) : Void

Concatenates a matrix with the current matrix, effectively combining the geometric effects of the two.

 

createBox(scaleX:Number, scaleY:Number, [rotation:Number], [tx:Number], [ty:Number]) : Void

Includes parameters for scaling, rotation, and translation.

 

createGradientBox(width:Number, height:Number, [rotation:Number], [tx:Number], [ty:Number]) : Void

Creates the specific style of matrix expected by the MovieClip.beginGradientFill() method.

 

deltaTransformPoint(pt:Point) : Point

Given a point in the pretransform coordinate space, returns the coordinates of that point after the transformation occurs.

 

identity() : Void

Sets each matrix property to a value that cause a transformed movie clip or geometric construct to be identical to the original.

 

invert() : Void

Performs the opposite transformation of the original matrix.

 

rotate(angle:Number) : Void

Sets the values in the current matrix so that the matrix can be used to apply a rotation transformation.

 

scale(sx:Number, sy:Number) : Void

Modifies a matrix so that its effect, when applied, is to resize an image.

 

toString() : String

Returns a text value listing the properties of the Matrix object.

 

transformPoint(pt:Point) : Point

Applies the geometric transformation represented by the Matrix object to the specified point.

 

translate(tx:Number, ty:Number) : Void

Modifies a Matrix object so that the effect of its transformation is to move an object along the x and y axes.

Methods inherited from class Object

addProperty, hasOwnProperty, isPropertyEnumerable, isPrototypeOf, registerClass, toString, unwatch, valueOf, watch



Version 8

Comments


shimi2 said on Jan 20, 2006 at 4:28 PM :
Minor typo:
The text "Together these types of transformations are knows as"
should be:
"Together these types of transformations are known as"

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00002389.html