flash.geomUtils3D The Utils3D class contains static methods that simplify the implementation of certain three-dimensional matrix operations.A utility class with static methods that simplify the implementation of certain three-dimensional operation. Object The Utils3D class contains static methods that simplify the implementation of certain three-dimensional matrix operations. flash.geom.Matrix3Dflash.geom.Vector3Dflash.geom.Transformflash.geom.PerspectiveProjectionflash.display.Graphicsflash.display.GraphicsTrianglePathVectorpointTowards Interpolates the orientation of an object toward a position.A modified version of the Matrix3D object specified in the second parameter. To transform the display object using the pointTowards() method, set the Matrix3D property of the display object to the returned Matrix3D object. flash.geom:Matrix3DpercentNumberA Number between 0 and 1 that incrementally turns the object toward the target. matflash.geom:Matrix3DThe Matrix3D property of the object that is transformed. posflash.geom:Vector3DThe world-relative position of the target object. World-relative defines the transformation of the object relative to the world space and coordinates, where all objects are positioned. atflash.geom:Vector3DnullThe object-relative vector that defines where the display object is pointing. Object-relative defines the transformation of the object relative to the object space, the object's own frame of reference and coordinate system. Default value is (0,0,-1). upflash.geom:Vector3DnullThe object-relative vector that defines "up" for the display object. If the object is drawn looking down from the above, the +z axis is its "up" vector. Object-relative defines the transformation of the object relative to the object space, the object's own frame of reference and coordinate system. Default value is (0,-1,0). Interpolates the orientation of an object toward a position. The pointTowards() method combines the functionality of the Matrix3D.pointAt() and Matrix3D.interpolateTo() methods.

The pointTowards() method allows for in-place modification to the orientation. It decomposes the Matrix3D of the display object and replaces the rotation elements by ones that make a percent turn toward the position of the target. The object can make an incremental turn toward the target while still moving in its own direction. The consecutive calls to the pointTowards() followed by a translation method can produce the animation of an object chasing or following a moving target. First point the object a percent point toward the target, then incrementally move the object along an axis.

flash.geom.Matrix3D.pointAt()flash.geom.Matrix3D.interpolateTo()flash.geom.Matrix3D.interpolate()
projectVectors Using a projection Matrix3D object, projects a Vector of three-dimensional space coordinates (verts) to a Vector of two-dimensional space coordinates (projectedVerts).mflash.geom:Matrix3DA projection Matrix3D object that implements the projection transformation. You can produce a projection Matrix3D object using the Matrix3D.rawData property. vertsA Vector of Numbers, where every three Numbers represent the x, y, and z coordinates of a three-dimensional space, like Vector3D(x,y,z). projectedVertsA vector of Numbers, where every two Numbers represent a projected two-dimensional coordinate, like Point(x,y). You should pre-allocate the Vector. The projectVectors() method fills the values for each projected point. uvtsA vector of Numbers, where every three Numbers represent the u, v, and t elements of the uvt data. The u and v are the texture coordinate for each projected point. The t value is the projection depth value, the distance from the eye to the Vector3D object in the view or eye space. You should pre-allocate the Vector and specify the u and v values. The projectVectors method fills the t value for each projected point. Projects a Vector of three-dimensional space coordinates to a Vector of two-dimensional space coordinates. Using a projection Matrix3D object, projects a Vector of three-dimensional space coordinates (verts) to a Vector of two-dimensional space coordinates (projectedVerts). The projected Vector object should be pre-allocated before it is used as a parameter.

The projectVectors() method also sets the t value of the uvt data. You should pre-allocate a Vector that can hold the uvts data for each projected Vector set of coordinates. Also specify the u and v values of the uvt data. The uvt data is a Vector of normalized coordinates used for texture mapping. In UV coordinates, (0,0) is the upper left of the bitmap, and (1,1) is the lower right of the bitmap.

This method can be used in conjunction with the Graphics.drawTriangles() method and the GraphicsTrianglePath class.

flash.display.Graphics.drawTriangles()flash.display.GraphicsTrianglePathflash.geom.Matrix3DprojectVector()Vector
projectVector Using a projection Matrix3D object, projects a Vector3D object from one space coordinate to another.A new Vector3D with a transformed space coordinate. flash.geom:Vector3Dmflash.geom:Matrix3DA projection Matrix3D object that implements the projection transformation. If a display object has a PerspectiveProjection object, you can use the perspectiveProjection.toMatrix() method to produce a projection Matrix3D object that applies to the children of the display object. For more advance projections, use the matrix3D.rawData property to create a custom projection matrix. There is no built-in Matrix3D method for creating a projection Matrix3D object. vflash.geom:Vector3DThe Vector3D object that is projected to a new space coordinate. Using a projection Matrix3D object, projects a Vector3D object from one space coordinate to another. The projectVector() method is like the Matrix3D.transformVector() method except that the projectVector() method divides the x, y, and z elements of the original Vector3D object by the projection depth value. The depth value is the distance from the eye to the Vector3D object in view or eye space. The default value for this distance is the value of the z element. flash.geom.Matrix3D.transformVector()projectVectors()
Vector3D The Vector3D class represents a point or a location in the three-dimensional space using the Cartesian coordinates x, y, and z.Object The Vector3D class represents a point or a location in the three-dimensional space using the Cartesian coordinates x, y, and z. As in a two-dimensional space, the x property represents the horizontal axis and the y property represents the vertical axis. In three-dimensional space, the z property represents depth. The value of the x property increases as the object moves to the right. The value of the y property increases as the object moves down. The z property increases as the object moves farther from the point of view. Using perspective projection and scaling, the object is seen to be bigger when near and smaller when farther away from the screen. As in a right-handed three-dimensional coordinate system, the positive z-axis points away from the viewer and the value of the z property increases as the object moves away from the viewer's eye. The origin point (0,0,0) of the global space is the upper-left corner of the stage.

The Vector3D class can also represent a direction, an arrow pointing from the origin of the coordinates, such as (0,0,0), to an endpoint; or a floating-point component of an RGB (Red, Green, Blue) color model.

Quaternion notation introduces a fourth element, the w property, which provides additional orientation information. For example, the w property can define an angle of rotation of a Vector3D object. The combination of the angle of rotation and the coordinates x, y, and z can determine the display object's orientation. Here is a representation of Vector3D elements in matrix notation:

flash.display.DisplayObjectflash.geom.Pointflash.geom.Matrix3Dflash.geom.Utils3DVectorVector3D Creates an instance of a Vector3D object.xNumber0.The first element, such as the x coordinate. yNumber0.The second element, such as the y coordinate. zNumber0.The third element, such as the z coordinate. wNumber0.An optional element for additional data such as the angle of rotation. Creates an instance of a Vector3D object. If you do not specify a parameter for the constructor, a Vector3D object is created with the elements (0,0,0,0). add Adds the value of the x, y, and z elements of the current Vector3D object to the values of the x, y, and z elements of another Vector3D object.A Vector3D object that is the result of adding the current Vector3D object to another Vector3D object. flash.geom:Vector3Daflash.geom:Vector3DA Vector3D object to be added to the current Vector3D object. Adds the current Vector3D object to another in order to create a new Vector3D object. Adds the value of the x, y, and z elements of the current Vector3D object to the values of the x, y, and z elements of another Vector3D object. The add() method does not change the current Vector3D object. Instead, it returns a new Vector3D object with the new values.

The result of adding two vectors together is a resultant vector. One way to visualize the result is by drawing a vector from the origin or tail of the first vector to the end or head of the second vector. The resultant vector is the distance between the origin point of the first vector and the end point of the second vector.

incrementBy()
angleBetween Returns the angle in radians between two vectors.The angle between two Vector3D objects. Numberaflash.geom:Vector3DThe first Vector3D object. bflash.geom:Vector3DThe second Vector3D object. Returns the angle in radians between two vectors. The returned angle is the smallest radian the first Vector3D object rotates until it aligns with the second Vector3D object.

The angleBetween() method is a static method. You can use it directly as a method of the Vector3D class.

To convert a degree to a radian, you can use the following formula:

radian = Math.PI/180 ~~ degree

clone Returns a new Vector3D object that is an exact copy of the current Vector3D object.A new Vector3D object that is a copy of the current Vector3D object. flash.geom:Vector3D Returns a new Vector3D object that is an exact copy of the current Vector3D object. crossProduct Returns a new Vector3D object that is perpendicular (at a right angle) to the current Vector3D and another Vector3D object.A new Vector3D object that is perpendicular to the current Vector3D object and the Vector3D object specified as the parameter. flash.geom:Vector3Daflash.geom:Vector3DA second Vector3D object. Returns a new Vector3D object that is perpendicular (at a right angle) to the current Vector3D and another Vector3D object. If the returned Vector3D object's coordinates are (0,0,0), then the two Vector3D objects are perpendicular to each other.

You can use the normalized cross product of two vertices of a polygon surface with the normalized vector of the camera or eye viewpoint to get a dot product. The value of the dot product can identify whether a surface of a three-dimensional object is hidden from the viewpoint.

dotProduct()normalize()
decrementBy Decrements the value of the x, y, and z elements of the current Vector3D object by the values of the x, y, and z elements of specified Vector3D object.aflash.geom:Vector3DThe Vector3D object containing the values to subtract from the current Vector3D object. Decrements the current Vector3D object by another Vector3D object. Decrements the value of the x, y, and z elements of the current Vector3D object by the values of the x, y, and z elements of specified Vector3D object. Unlike the Vector3D.subtract() method, the decrementBy() method changes the current Vector3D object and does not return a new Vector3D object. subtract()distance Returns the distance between two Vector3D objects.The distance between two Vector3D objects. Numberpt1flash.geom:Vector3DA Vector3D object as the first three-dimensional point. pt2flash.geom:Vector3DA Vector3D object as the second three-dimensional point. Returns the distance between two Vector3D objects. The distance() method is a static method. You can use it directly as a method of the Vector3D class to get the Euclidean distance between two three-dimensional points. dotProduct If the current Vector3D object and the one specified as the parameter are unit vertices, this method returns the cosine of the angle between the two vertices.A scalar which is the dot product of the current Vector3D object and the specified Vector3D object. Numberaflash.geom:Vector3DThe second Vector3D object. Returns the dot product of current and another Vector3D object. If the current Vector3D object and the one specified as the parameter are unit vertices, this method returns the cosine of the angle between the two vertices. Unit vertices are vertices that point to the same direction but their length is one. They remove the length of the vector as a factor in the result. You can use the normalize() method to convert a vector to a unit vector.

The dotProduct() method finds the angle between two vertices. It is also used in backface culling or lighting calculations. Backface culling is a procedure for determining which surfaces are hidden from the viewpoint. You can use the normalized vertices from the camera, or eye, viewpoint and the cross product of the vertices of a polygon surface to get the dot product. If the dot product is less than zero, then the surface is facing the camera or the viewer. If the two unit vertices are perpendicular to each other, they are orthogonal and the dot product is zero. If the two vertices are parallel to each other, the dot product is one.

crossProduct()normalize()
equals Determines whether two Vector3D objects are equal by comparing the x, y, and z elements of the current Vector3D object with a specified Vector3D object.A value of true if the specified Vector3D object is equal to the current Vector3D object; false if it is not equal. BooleantoCompareflash.geom:Vector3DThe Vector3D object to be compared with the current Vector3D object. allFourBooleanfalseAn optional parameter that specifies whether the w property of the Vector3D objects is used in the comparison. Determines whether two Vector3D objects are equal by comparing the x, y, and z elements of the current Vector3D object with a specified Vector3D object. If the values of these elements are the same, the two Vector3D objects are equal. If the second optional parameter is set to true, all four elements of the Vector3D objects, including the w property, are compared. nearEquals()incrementBy Increments the value of the x, y, and z elements of the current Vector3D object by the values of the x, y, and z elements of a specified Vector3D object.aflash.geom:Vector3DThe Vector3D object to be added to the current Vector3D object. Increments the current Vector3D object by another Vector3D object. Increments the value of the x, y, and z elements of the current Vector3D object by the values of the x, y, and z elements of a specified Vector3D object. Unlike the Vector3D.add() method, the incrementBy() method changes the current Vector3D object and does not return a new Vector3D object. add()nearEquals Compares the elements of the current Vector3D object with the elements of a specified Vector3D object to determine whether they are nearly equal.A value of true if the specified Vector3D object is nearly equal to the current Vector3D object; false if it is not equal. BooleantoCompareflash.geom:Vector3DThe Vector3D object to be compared with the current Vector3D object. toleranceNumberA number determining the tolerance factor. If the difference between the values of the Vector3D element specified in the toCompare parameter and the current Vector3D element is less than the tolerance number, the two values are considered nearly equal. allFourBooleanfalseAn optional parameter that specifies whether the w property of the Vector3D objects is used in the comparison. Compares the elements of the current Vector3D object with the elements of a specified Vector3D object to determine whether they are nearly equal. The two Vector3D objects are nearly equal if the value of all the elements of the two vertices are equal, or the result of the comparison is within the tolerance range. The difference between two elements must be less than the number specified as the tolerance parameter. If the third optional parameter is set to true, all four elements of the Vector3D objects, including the w property, are compared. Otherwise, only the x, y, and z elements are included in the comparison. equals()negate Sets the current Vector3D object to its inverse. Sets the current Vector3D object to its inverse. The inverse object is also considered the opposite of the original object. The value of the x, y, and z properties of the current Vector3D object is changed to -x, -y, and -z. normalize Converts a Vector3D object to a unit vector by dividing the first three elements (x, y, z) by the length of the vector.The length of the current Vector3D object. Number Converts a Vector3D object to a unit vector by dividing the first three elements (x, y, z) by the length of the vector. Unit vertices are vertices that have a direction but their length is one. They simplify vector calculations by removing length as a factor. project Divides the value of the x, y, and z properties of the current Vector3D object by the value of its w property. Divides the value of the x, y, and z properties of the current Vector3D object by the value of its w property.

If the current Vector3D object is the result of multiplying a Vector3D object by a projection Matrix3D object, the w property can hold the transform value. The project() method then can complete the projection by dividing the elements by the w property. Use the Matrix3D.rawData property to create a projection Matrix3D object.

scaleBy Scales the current Vector3D object by a scalar, a magnitude.sNumberA multiplier (scalar) used to scale a Vector3D object. Scales the current Vector3D object by a scalar, a magnitude. The Vector3D object's x, y, and z elements are multiplied by the scalar number specified in the parameter. For example, if the vector is scaled by ten, the result is a vector that is ten times longer. The scalar can also change the direction of the vector. Multiplying the vector by a negative number reverses its direction. subtract Subtracts the value of the x, y, and z elements of the current Vector3D object from the values of the x, y, and z elements of another Vector3D object.A new Vector3D object that is the difference between the current Vector3D and the specified Vector3D object. flash.geom:Vector3Daflash.geom:Vector3DThe Vector3D object to be subtracted from the current Vector3D object. Subtracts the current Vector3D from another Vector3D object in order to create a new Vector3D object. Subtracts the value of the x, y, and z elements of the current Vector3D object from the values of the x, y, and z elements of another Vector3D object. The subtract() method does not change the current Vector3D object. Instead, this method returns a new Vector3D object with the new values. decrementBy()toString Returns a string representation of the current Vector3D object.A string containing the values of the x, y, and z properties. String Returns a string representation of the current Vector3D object. The string contains the values of the x, y, and z properties. X_AXIS The x axis defined as a Vector3D object with coordinates (1,0,0).unknownflash.geom:Vector3D The x axis defined as a Vector3D object with coordinates (1,0,0). Y_AXIS The y axis defined as a Vector3D object with coordinates (0,1,0).unknownflash.geom:Vector3D The y axis defined as a Vector3D object with coordinates (0,1,0). Z_AXIS The z axis defined as a Vector3D object with coordinates (0,0,1).unknownflash.geom:Vector3D The z axis defined as a Vector3D object with coordinates (0,0,1). w The fourth element of a Vector3D object (in addition to the x, y, and z properties) can hold data such as the angle of rotation.Number The fourth element of a Vector3D object (in addition to the x, y, and z properties) can hold data such as the angle of rotation. The default value is 0.

Quaternion notation employs an angle as the fourth element in its calculation of three-dimensional rotation. The w property can be used to define the angle of rotation about the Vector3D object. The combination of the rotation angle and the coordinates (x,y,z) determines the display object's orientation.

In addition, the w property can be used as a perspective warp factor for a projected three-dimensional position or as a projection transform value in representing a three-dimensional coordinate projected into the two-dimensional space. For example, you can create a projection matrix using the Matrix3D.rawData property, that, when applied to a Vector3D object, produces a transform value in the Vector3D object's fourth element (the w property). Dividing the Vector3D object's other elements by the transform value then produces a projected Vector3D object. You can use the Vector3D.project() method to divide the first three elements of a Vector3D object by its fourth element.

project()
x The first element of a Vector3D object, such as the x coordinate of a point in the three-dimensional space.Number The first element of a Vector3D object, such as the x coordinate of a point in the three-dimensional space. The default value is 0. y The second element of a Vector3D object, such as the y coordinate of a point in the three-dimensional space.Number The second element of a Vector3D object, such as the y coordinate of a point in the three-dimensional space. The default value is 0. z The third element of a Vector3D object, such as the z coordinate of a point in three-dimensional space.Number The third element of a Vector3D object, such as the z coordinate of a point in three-dimensional space. The default value is 0. lengthSquared The square of the length of the current Vector3D object, calculated using the x, y, and z properties.NumberThe square of the length of the current Vector3D object. The square of the length of the current Vector3D object, calculated using the x, y, and z properties. The w property is ignored. Use the lengthSquared() method whenever possible instead of the slower Math.sqrt() method call of the Vector3D.length() method. lengthlength The length, magnitude, of the current Vector3D object from the origin (0,0,0) to the object's x, y, and z coordinates.NumberThe length of the current Vector3D object. The length, magnitude, of the current Vector3D object from the origin (0,0,0) to the object's x, y, and z coordinates. The w property is ignored. A unit vector has a length or magnitude of one. lengthSquared
Matrix3D The Matrix3D class represents a transformation matrix that determines the position and orientation of a three-dimensional (3D) display object.Object The Matrix3D class represents a transformation matrix that determines the position and orientation of a three-dimensional (3D) display object. The matrix can perform transformation functions including translation (repositioning along the x, y, and z axes), rotation, and scaling (resizing). The Matrix3D class can also perform perspective projection, which maps points from the 3D coordinate space to a two-dimensional (2D) view.

A single matrix can combine multiple transformations and apply them at once to a 3D display object. For example, a matrix can be applied to 3D coordinates to perform a rotation followed by a translation.

When you explicitly set the z property or any of the rotation or scaling properties of a display object, a corresponding Matrix3D object is automatically created.

You can access a 3D display object's Matrix3D object through the transform.matrix3d property. 2D objects do not have a Matrix3D object.

The value of the z property of a 2D object is zero and the value of its matrix3D property is null.

Note: If the same Matrix3D object is assigned to two different display objects, a runtime error is thrown.

The Matrix3D class uses a 4x4 square matrix: a table of four rows and columns of numbers that hold the data for the transformation. The first three rows of the matrix hold data for each 3D axis (x,y,z). The translation information is in the last column. The orientation and scaling data are in the first three columns. The scaling factors are the diagonal numbers in the first three columns. Here is a representation of Matrix3D elements:

You don't need to understand matrix mathematics to use the Matrix3D class. It offers specific methods that simplify the task of transformation and projection, such as the appendTranslation(), appendRotation(), or interpolateTo() methods. You also can use the decompose() and recompose() methods or the rawData property to access the underlying matrix elements.

Display objects cache their axis rotation properties to have separate rotation for each axis and to manage the different combinations of rotations. When a method of a Matrix3D object is called to transform a display object, the rotation cache of the object is invalidated.

flash.display.DisplayObjectflash.geom.Transformflash.geom.PerspectiveProjectionflash.geom.Vector3Dflash.geom.Orientation3Dflash.geom.Utils3Dflash.geom.MatrixMatrix3D Creates a Matrix3D object.vnullA Vector of 16 Numbers, where each four elements can be a row or a column of a 4x4 matrix. Creates a Matrix3D object. Matrix3D objects can be initialized with a Vector of 16 Numbers, where every four elements can be a row or a column. Once the Matrix3D object is created, you can access its matrix elements with the rawData property.

If no parameter is defined, the constructor produces an identity or unit Matrix3D object. In matrix notation, an identity matrix has a value of one for all elements on the main diagonal position and a value of zero for all other elements. The value of the rawData property of an identity matrix is: 1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1. The position or translation value of the identity matrix is Vector3D(0,0,0), the rotation setting is Vector3D(0,0,0), and the scale value is Vector3D(1,1,1).

identity()Vector
appendRotation Appends an incremental rotation to a Matrix3D object.degreesNumberThe degree of the rotation. axisflash.geom:Vector3DThe axis or direction of rotation. The usual axes are the X_AXIS (Vector3D(1,0,0)), Y_AXIS (Vector3D(0,1,0)), and Z_AXIS (Vector3D(0,0,1)). pivotPointflash.geom:Vector3DnullA point that determines the center of an object's rotation. The default pivot point for an object is its registration point. Appends an incremental rotation to a Matrix3D object. When the Matrix3D object is applied to a display object, the matrix performs the rotation after other transformations in the Matrix3D object.

The display object's rotation is defined by an axis, an incremental degree of rotation around the axis, and an optional pivot point for the center of the object's rotation. The axis can be any general direction. The common axes are the X_AXIS (Vector3D(1,0,0)), Y_AXIS (Vector3D(0,1,0)), and Z_AXIS (Vector3D(0,0,1)). In aviation terminology, the rotation about the y axis is called yaw. The rotation about the x axis is called pitch. The rotation about the z axis is called roll.

The order of transformation matters. A rotation followed by a translation transformation produces a different effect than a translation followed by a rotation transformation.

The rotation effect is not absolute. It is relative to the current position and orientation. To make an absolute change to the transformation matrix, use the recompose() method. The appendRotation() method is also different from the axis rotation property of the display object, such as rotationX property. The rotation property is always performed before any translation, whereas the appendRotation() method is performed relative to what is already in the matrix. To make sure that you get a similar effect as the display object's axis rotation property, use the prependRotation() method, which performs the rotation before other transformations in the matrix.

When the appendRotation() method's transformation is applied to a Matrix3D object of a display object, the cached rotation property values of the display object are invalidated.

One way to have a display object rotate around a specific point relative to its location is to set the translation of the object to the specified point, rotate the object using the appendRotation() method, and translate the object back to the original position. In the following example, the myObject 3D display object makes a y-axis rotation around the coordinate (10,10,0).

myObject.z = 1; myObject.transform.matrix3D.appendTranslation(10,10,0); myObject.transform.matrix3D.appendRotation(1, Vector3D.Y_AXIS); myObject.transform.matrix3D.appendTranslation(-10,-10,0);
prependRotation()
appendScale Appends an incremental scale change along the x, y, and z axes to a Matrix3D object.xScaleNumberA multiplier used to scale the object along the x axis. yScaleNumberA multiplier used to scale the object along the y axis. zScaleNumberA multiplier used to scale the object along the z axis. Appends an incremental scale change along the x, y, and z axes to a Matrix3D object. When the Matrix3D object is applied to a display object, the matrix performs the scale changes after other transformations in the Matrix3D object. The default scale factor is (1.0, 1.0, 1.0).

The scale is defined as a set of three incremental changes along the three axes (x,y,z). You can multiply each axis with a different number. When the scale changes are applied to a display object, the object's size increases or decreases. For example, setting the x, y, and z axes to two doubles the size of the object, while setting the axes to 0.5 halves the size. To make sure that the scale transformation only affects a specific axis, set the other parameters to one. A parameter of one means no scale change along the specific axis.

The appendScale() method can be used for resizing as well as for managing distortions, such as stretch or contract of a display object, or for zooming in and out on a location. Scale transformations are automatically performed during a display object's rotation and translation.

The order of transformation matters. A resizing followed by a translation transformation produces a different effect than a translation followed by a resizing transformation.

prependScale()
appendTranslation Appends an incremental translation, a repositioning along the x, y, and z axes, to a Matrix3D object.xNumberAn incremental translation along the x axis. yNumberAn incremental translation along the y axis. zNumberAn incremental translation along the z axis. Appends an incremental translation, a repositioning along the x, y, and z axes, to a Matrix3D object. When the Matrix3D object is applied to a display object, the matrix performs the translation changes after other transformations in the Matrix3D object.

The translation is defined as a set of three incremental changes along the three axes (x,y,z). When the transformation is applied to a display object, the display object moves from it current location along the x, y, and z axes as specified by the parameters. To make sure that the translation only affects a specific axis, set the other parameters to zero. A zero parameter means no change along the specific axis.

The translation changes are not absolute. They are relative to the current position and orientation of the matrix. To make an absolute change to the transformation matrix, use the recompose() method. The order of transformation also matters. A translation followed by a rotation transformation produces a different effect than a rotation followed by a translation.

prependTranslation()position
append Appends the matrix by multiplying another Matrix3D object by the current Matrix3D object.lhsflash.geom:Matrix3DA left-hand-side matrix that is multiplied by the current Matrix3D object. Appends the matrix by multiplying another Matrix3D object by the current Matrix3D object. The result combines both matrix transformations. You can multiply a Matrix3D object by many matrixes. The final Matrix3D object contains the result of all the transformations.

Matrix multiplication is different from matrix addition. Matrix multiplication is not commutative. In other words, A times B is not equal to B times A. With the append() method, the multiplication happens from the left side, meaning the lhs Matrix3D object is on the left side of the multiplication operator.

thisMatrix = lhs ~~ thisMatrix;

The first time the append() method is called, it makes a modification relative to the parent space. Subsequent calls are relative to the frame of reference of the appended Matrix3D object.

The append() method replaces the current matrix with the appended matrix. If you want to append two matrixes without altering the current matrix, copy the current matrix by using the clone() method and then apply the append() method to the copy.

flash.geom.Matrix3D.prepend()
clone Returns a new Matrix3D object that is an exact copy of the current Matrix3D object.A new Matrix3D object that is an exact copy of the current Matrix3D object. flash.geom:Matrix3D Returns a new Matrix3D object that is an exact copy of the current Matrix3D object. decompose Returns the transformation matrix's translation, rotation, and scale settings as a Vector of three Vector3D objects.A Vector of three Vector3D objects, each holding the translation, rotation, and scale settings, respectively. orientationStyleStringeulerAnglesAn optional parameter that determines the orientation style used for the matrix transformation. The three types of orientation style are eulerAngles (constant EULER_ANGLES), axisAngle (constant AXIS_ANGLE), and quaternion (constant QUATERNION). For additional information on the different orientation style, see the geom.Orientation3D class. Returns the transformation matrix's translation, rotation, and scale settings as a Vector of three Vector3D objects. The first Vector3D object holds the translation elements. The second Vector3D object holds the rotation elements. The third Vector3D object holds the scale elements.

Some Matrix3D methods, such as the interpolateTo() method, automatically decompose and recompose the matrix to perform their transformation.

To modify the matrix's transformation with an absolute parent frame of reference, retrieve the settings with the decompose() method and make the appropriate changes. You can then set the Matrix3D object to the modified transformation using the recompose() method.

The decompose() method's parameter specifies the orientation style that is meant to be used for the transformation. The default orientation is eulerAngles, which defines the orientation with three separate angles of rotation for each axis. The rotations occur consecutively and do not change the axis of each other. The display object's axis rotation properties perform Euler Angles orientation style transformation. The other orientation style options are axisAngle and quaternion. The Axis Angle orientation uses a combination of an axis and an angle to determine the orientation. The axis around which the object is rotated is a unit vector that represents a direction. The angle represents the magnitude of the rotation about the vector. The direction also determines where a display object is facing and the angle determines which way is up. The appendRotation() and prependRotation() methods use the Axis Angle orientation. The quaternion orientation uses complex numbers and the fourth element of a vector. The three axes of rotation (x,y,z) and an angle of rotation (w) represent the orientation. The interpolate() method uses quaternion.

This example uses the decompose() and recompose() methods to have an ellipse stretch horizontally while moving toward the vanishing point. The first Vector3D object returned by the decompose() method holds the translation coordinates. The third Vector3D object holds the scale settings. The Vector3D object's incrementBy() method increments the matrix's absolute translation and scale settings. package { import flash.display.MovieClip; import flash.display.Shape; import flash.geom.*; import flash.events.Event; public class Matrix3DdecomposeExample extends MovieClip { private var ellipse:Shape = new Shape(); public function Matrix3DdecomposeExample():void { ellipse.x = (this.stage.stageWidth / 2); ellipse.y = (this.stage.stageHeight - 40); ellipse.z = 1; ellipse.graphics.beginFill(0xFF0000); ellipse.graphics.lineStyle(2); ellipse.graphics.drawEllipse(0, 0, 50, 40); ellipse.graphics.endFill(); addChild(ellipse); ellipse.addEventListener(Event.ENTER_FRAME, enterFrameHandler); } private function enterFrameHandler(e:Event):void { var v3:Vector.<Vector3D> = new Vector.<Vector3D>(3); v3 = ellipse.transform.matrix3D.decompose(); v3[0].incrementBy(new Vector3D(0,0,1)); v3[2].incrementBy(new Vector3D(0.01,0,0)); ellipse.transform.matrix3D.recompose(v3); } } }
flash.geom.Orientation3Drecompose()Vector
deltaTransformVector Uses the transformation matrix without its translation elements to transform a Vector3D object from one space coordinate to another.A Vector3D object with the transformed coordinates. flash.geom:Vector3Dvflash.geom:Vector3DA Vector3D object holding the coordinates that are going to be transformed. Uses the transformation matrix without its translation elements to transform a Vector3D object from one space coordinate to another. The returned Vector3D object holds the new coordinates after the rotation and scaling transformations have been applied. If the deltaTransformVector() method applies a matrix that only contains a translation transformation, the returned Vector3D is the same as the original Vector3D object.

You can use the deltaTransformVector() method to have a display object in one coordinate space respond to the rotation transformation of a second display object. The object does not copy the rotation; it only changes its position to reflect the changes in the rotation. For example, to use the display.Graphics API for drawing a rotating 3D display object, you must map the object's rotating coordinates to a 2D point. First, retrieve the object's 3D coordinates after each rotation, using the deltaTransformVector() method. Next, apply the display object's local3DToGlobal() method to translate the 3D coordinates to 2D points. You can then use the 2D points to draw the rotating 3D object.

transformVectors()transformVector()
identity Converts the current matrix to an identity or unit matrix. Converts the current matrix to an identity or unit matrix. An identity matrix has a value of one for the elements on the main diagonal and a value of zero for all other elements. The result is a matrix where the rawData value is 1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1 and the rotation setting is set to Vector3D(0,0,0), the position or translation setting is set to Vector3D(0,0,0), and the scale is set to Vector3D(1,1,1). Here is a representation of an identity matrix.

An object transformed by applying an identity matrix performs no transformation. In other words, if a matrix is multiplied by an identity matrix, the result is a matrix that is the same as (identical to) the original matrix.

interpolateTo Interpolates the display object's matrix a percent closer to a target's matrix.toMatflash.geom:Matrix3DThe target Matrix3D object. percentNumberA value between 0 and 1 that determines the location of the display object relative to the target. The closer the value is to 1.0, the closer the display object is to its current position. The closer the value is to 0, the closer the display object is to the target. Interpolates the display object's matrix a percent closer to a target's matrix. All the elements for translation, rotation, and scale of the display object are interpolated to values between the current and target display object's matrix.

The interpolateTo() method avoids the unwanted results that can occur when using methods such as the display object's axis rotation properties. The interpolateTo() method invalidates the cached value of the rotation property of the display object and converts the orientation elements of the display object's matrix to a quaternion before interpolation. This method guarantees the shortest, most efficient path for the rotation. It also produces a smooth, gimbal-lock-free rotation. A gimbal lock can occur when using Euler Angles, where each axis is handled independently. During the rotation around two or more axes, the axes can become aligned, leading to unexpected results. Quaternion rotation avoids the gimbal lock.

Consecutive calls to the interpolateTo() method can produce the effect of a display object starting quickly and then slowly approaching another display object. For example, if the percent parameter is set to 0.1, the display object moves ten percent toward the target object specified by the toMat parameter. On subsequent calls or in subsequent frames, the object moves ten percent of the remaining 90 percent, then ten percent of the remaining 80 percent, until it reaches the target.

In this example, ellipse2, a three-dimensional display object, goes toward ellipse1, another three-dimensional display object. ellipse2 follows ellipse1 around trying to catch it. If ellipse1 does not rotate around its y axis, ellipse2 will reach and land on top of ellipse1. The two ellipses are drawn in the same way but are placed in different three-dimensional world-space locations. package { import flash.display.MovieClip; import flash.display.Shape; import flash.display.Graphics; import flash.geom.*; import flash.events.Event; public class InterpolateToExample extends MovieClip { private var ellipse1:Shape = new Shape(); private var ellipse2:Shape = new Shape(); public function InterpolateToExample():void { ellipse1 = myEllipses(250, 100, 500, 0xFF0000); addChild(ellipse1); ellipse2 = myEllipses(-30, 120, 1, 0x00FF00); addChild(ellipse2); addEventListener(Event.ENTER_FRAME, enterFrameHandler); } private function myEllipses(x:Number, y:Number, z:Number, c:Number):Shape { var s:Shape = new Shape(); s.x = x; s.y = y; s.z = z; s.graphics.beginFill(c); s.graphics.lineStyle(2); s.graphics.drawEllipse(100, 50, 100, 80); s.graphics.endFill(); return s; } private function enterFrameHandler(e:Event) { ellipse1.rotationY += 1; ellipse2.transform.matrix3D.interpolateTo(ellipse1.transform.matrix3D, 0.1); } } }
interpolate()
interpolate Simplifies the interpolation from one frame of reference to another by interpolating a display object a percent point closer to a target display object.A Matrix3D object with elements that place the values of the matrix between the original matrix and the target matrix. When the returned matrix is applied to the this display object, the object moves the specified percent closer to the target object. flash.geom:Matrix3DthisMatflash.geom:Matrix3DThe Matrix3D object that is to be interpolated. toMatflash.geom:Matrix3DThe target Matrix3D object. percentNumberA value between 0 and 1 that determines the percent the thisMat Matrix3D object is interpolated toward the target Matrix3D object. Interpolates a display object a percent point closer to a target display object. Simplifies the interpolation from one frame of reference to another by interpolating a display object a percent point closer to a target display object. The result is a new Matrix3D object where all the elements for the translation, rotation, and scale are interpolated to values between the current display object and the target display object.

The interpolate() method avoids some of the unwanted results that can occur when using methods such as the display object's axis rotation properties. The interpolate() method invalidates the cached value of the rotation property of the display object and converts the orientation elements of the display object's matrix to a quaternion before interpolation. This method guarantees the shortest, most efficient path for the rotation. It also produces a smooth, gimbal-lock-free rotation. A gimbal lock can occur when using Euler Angles, where each axis is handled independently. During the rotation around two or more axes, the axes can become aligned, leading to unexpected results. Quaternion rotation avoids the gimbal lock.

Consecutive calls to the interpolate() method can produce the effect of a display object starting quickly and then slowly approaching another display object. For example, if you set the thisMat parameter to the returned Matrix3D object, the toMat parameter to the target display object's associated Matrix3D object, and the percent parameter to 0.1, the display object moves ten percent toward the target object. On subsequent calls or in subsequent frames, the object moves ten percent of the remaining 90 percent, then ten percent of the remaining 80 percent, until it reaches the target.

interpolateTo()flash.geom.Utils3D.pointTowards()
invert Inverts the current matrix.Returns true if the matrix was successfully inverted. Boolean Inverts the current matrix. An inverted matrix is the same size as the original but performs the opposite transformation of the original matrix. For example, if the original matrix has an object rotate around the x axis in one direction, the inverse of the matrix will have the object rotate around the axis in the opposite direction. Applying an inverted matrix to an object undoes the transformation performed by the original matrix. If a matrix is multiplied by its inverse matrix, the result is an identity matrix.

An inverse of a matrix can be used to divide one matrix by another. The way to divide matrix A by matrix B is to multiply matrix A by the inverse of matrix B. The inverse matrix can also be used with a camera space. When the camera moves in the world space, the object in the world needs to move in the opposite direction to transform from the world view to the camera or view space. For example, if the camera moves closer, the objects becomes bigger. In other words, if the camera moves down the world z axis, the object moves up world z axis.

The invert() method replaces the current matrix with an inverted matrix. If you want to invert a matrix without altering the current matrix, first copy the current matrix by using the clone() method and then apply the invert() method to the copy.

The Matrix3D object must be invertible.

determinant
pointAt Rotates the display object so that it faces a specified position.posflash.geom:Vector3DThe world-relative position of the target object. World-relative defines the object's transformation relative to the world space and coordinates, where all objects are positioned. atflash.geom:Vector3DnullThe object-relative vector that defines where the display object is pointing. Object-relative defines the object's transformation relative to the object space, the object's own frame of reference and coordinate system. Default value is the +y axis (0,1,0). upflash.geom:Vector3DnullThe object-relative vector that defines "up" for the display object. If the object is drawn looking down from above, the +z axis is its "up" vector. Object-relative defines the object's transformation relative to the object space, the object's own frame of reference and coordinate system. Default value is the +z-axis (0,0,1). Rotates the display object so that it faces a specified position. This method allows for an in-place modification to the orientation. The forward direction vector of the display object (the at Vector3D object) points at the specified world-relative position. The display object's up direction is specified with the up Vector3D object.

The pointAt() method invalidates the cached rotation property value of the display object. The method decomposes the display object's matrix and modifies the rotation elements to have the object turn to the specified position. It then recomposes (updates) the display object's matrix, which performs the transformation. If the object is pointing at a moving target, such as a moving object's position, then with each subsequent call, the method has the object rotate toward the moving target.

Note: If you use the Matrix3D.pointAt() method without setting the optional parameters, a target object does not face the specified world-relative position by default. You need to set the values for at to the -y-axis (0,-1,0) and up to the -z axis (0,0,-1).

In this example, a triangle points and follows the path of the ellipse's movement. The ellipse and triangle are set to different locations. The ellipse then moves up toward the corner of the stage. The triangle follows the ellipse's translation changes. You can change the triangle's shape and the "at" and "up" parameters of the pointAt() to see their impacts on the triangle's movement. package { import flash.display.MovieClip; import flash.display.Shape; import flash.display.Graphics; import flash.geom.*; import flash.events.Event; public class PointAtExample extends MovieClip { private var ellipse:Shape = new Shape(); private var triangle:Shape = new Shape(); public function PointAtExample():void { ellipse.graphics.beginFill(0xFF0000); ellipse.graphics.lineStyle(2); ellipse.graphics.drawEllipse(30, 40, 50, 40); ellipse.graphics.endFill(); ellipse.x = 100; ellipse.y = 150; ellipse.z = 1; triangle.graphics.beginFill(0x0000FF); triangle.graphics.moveTo(0, 0); triangle.graphics.lineTo(40, 40); triangle.graphics.lineTo(80, 0); triangle.graphics.lineTo(0, 0); triangle.graphics.endFill(); triangle.x = 200; triangle.y = 50; triangle.z = 1; addChild(ellipse); addChild(triangle); ellipse.addEventListener(Event.ENTER_FRAME, ellipseEnterFrameHandler); triangle.addEventListener(Event.ENTER_FRAME, triangleEnterFrameHandler); } private function ellipseEnterFrameHandler(e:Event) { if(e.target.y > 0) { e.target.y -= 1; e.target.x -= 1; } } private function triangleEnterFrameHandler(e:Event) { e.target.transform.matrix3D.pointAt(ellipse.transform.matrix3D.position, Vector3D.X_AXIS, Vector3D.Y_AXIS); } } }
flash.geom.Utils3D.pointTowards()
prependRotation Prepends an incremental rotation to a Matrix3D object.degreesNumberThe degree of rotation. axisflash.geom:Vector3DThe axis or direction of rotation. The usual axes are the X_AXIS (Vector3D(1,0,0)), Y_AXIS (Vector3D(0,1,0)), and Z_AXIS (Vector3D(0,0,1)). pivotPointflash.geom:Vector3DnullA point that determines the center of rotation. The default pivot point for an object is its registration point. Prepends an incremental rotation to a Matrix3D object. When the Matrix3D object is applied to a display object, the matrix performs the rotation before other transformations in the Matrix3D object.

The display object's rotation is defined by an axis, an incremental degree of rotation around the axis, and an optional pivot point for the center of the object's rotation. The axis can be any general direction. The common axes are the X_AXIS (Vector3D(1,0,0)), Y_AXIS (Vector3D(0,1,0)), and Z_AXIS (Vector3D(0,0,1)). In aviation terminology, the rotation about the y axis is called yaw. The rotation about the x axis is called pitch. The rotation about the z axis is called roll.

The order of transformation matters. A rotation followed by a translation transformation produces a different effect than a translation followed by a rotation.

The rotation effect is not absolute. The effect is object-relative, relative to the frame of reference of the original position and orientation. To make an absolute change to the transformation, use the recompose() method.

When the prependRotation() method's transformation is applied to a Matrix3D object of a display object, the cached rotation property values of the display object are invalidated.

One way to have a display object rotate around a specific point relative to its location is to set the translation of the object to the specified point, rotate the object using the prependRotation() method, and translate the object back to the original position. In the following example, the myObject 3D display object makes a y-axis rotation around the coordinate (10,10,0).

myObject.z = 1; myObject.transform.matrix3D.prependTranslation(10,10,0); myObject.transform.matrix3D.prependRotation(1, Vector3D.Y_AXIS); myObject.transform.matrix3D.prependTranslation(-10,-10,0);
In this example, the user can move a mouse to rotate an ellipse around its x and y axes. The ellipse is drawn with its registration point in its center. The ellipse rotates around its y axis using the mouse's x coordinate. It rotates around its x axis using the mouse's y coordinate. package { import flash.display.MovieClip; import flash.display.Shape; import flash.geom.*; import flash.events.MouseEvent; public class Matrix3DprependRotationExample extends MovieClip { private var ellipse:Shape = new Shape(); public function Matrix3DprependRotationExample():void { ellipse.graphics.beginFill(0xFF0000); ellipse.graphics.lineStyle(2); ellipse.graphics.drawEllipse(-50, -40, 100, 80); ellipse.graphics.endFill(); ellipse.x = (this.stage.stageWidth / 2); ellipse.y = (this.stage.stageHeight / 2); ellipse.z = 1; addChild(ellipse); stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler); } private function mouseMoveHandler(e:MouseEvent):void { var y:int; var x:int; if(e.localX > ellipse.x) { y = (Math.round(e.localX) / 100); } else { y = -(Math.round(e.localX) / 10); } if(e.localY > ellipse.y) { x = (Math.round(e.localY) / 100); } else { x = -(Math.round(e.localY) / 100); } ellipse.transform.matrix3D.prependRotation(y, Vector3D.Y_AXIS); ellipse.transform.matrix3D.prependRotation(x, Vector3D.X_AXIS); } } }
appendRotation()
prependScale Prepends an incremental scale change along the x, y, and z axes to a Matrix3D object.xScaleNumberA multiplier used to scale the object along the x axis. yScaleNumberA multiplier used to scale the object along the y axis. zScaleNumberA multiplier used to scale the object along the z axis. Prepends an incremental scale change along the x, y, and z axes to a Matrix3D object. When the Matrix3D object is applied to a display object, the matrix performs the scale changes before other transformations in the Matrix3D object. The changes are object-relative, relative to the frame of reference of the original position and orientation. The default scale factor is (1.0, 1.0, 1.0).

The scale is defined as a set of three incremental changes along the three axes (x,y,z). You can multiply each axis with a different number. When the scale changes are applied to a display object, the object's size increases or decreases. For example, setting the x, y, and z axes to two doubles the size of the object, while setting the axes to 0.5 halves the size. To make sure that the scale transformation only affects a specific axis, set the other parameters to one. A parameter of one means no scale change along the specific axis.

The prependScale() method can be used for resizing as well as for managing distortions, such as stretch or contract of a display object. It can also be used for zooming in and out on a location. Scale transformations are automatically performed during a display object's rotation and translation.

The order of transformation matters. A resizing followed by a translation transformation produces a different effect than a translation followed by a resizing transformation.

appendScale()
prependTranslation Prepends an incremental translation, a repositioning along the x, y, and z axes, to a Matrix3D object.xNumberAn incremental translation along the x axis. yNumberAn incremental translation along the y axis. zNumberAn incremental translation along the z axis. Prepends an incremental translation, a repositioning along the x, y, and z axes, to a Matrix3D object. When the Matrix3D object is applied to a display object, the matrix performs the translation changes before other transformations in the Matrix3D object.

Translation specifies the distance the display object moves from its current location along the x, y, and z axes. The prependTranslation() method sets the translation as a set of three incremental changes along the three axes (x,y,z). To have a translation change only a specific axis, set the other parameters to zero. A zero parameter means no change along the specific axis.

The translation changes are not absolute. The effect is object-relative, relative to the frame of reference of the original position and orientation. To make an absolute change to the transformation matrix, use the recompose() method. The order of transformation also matters. A translation followed by a rotation transformation produces a different effect than a rotation followed by a translation transformation. When prependTranslation() is used, the display object continues to move in the direction it is facing, regardless of the other transformations. For example, if a display object was facing toward a positive x axis, it continues to move in the direction specified by the prependTranslation() method, regardless of how the object has been rotated. To make translation changes occur after other transformations, use the appendTranslation() method.

In this example, the user can push an ellipse up the stage's y axis using a mouse. When the user moves the mouse over the ellipse, the ellipse jumps ten coordinates up the y axis. When the mouse moves off of the ellipse, if the ellipse has not reached the top, the ellipse again jumps ten coordinates up the y axis. Once the ellipse reaches the top, it is moved back to the bottom of the stage. package { import flash.display.MovieClip; import flash.display.Sprite; import flash.geom.*; import flash.events.MouseEvent; public class Matrix3DprependTranslationExample extends MovieClip { private var ellipse:Sprite = new Sprite(); public function Matrix3DprependTranslationExample():void { ellipse.x = this.stage.stageWidth / 2; ellipse.y = this.stage.stageHeight - 100; ellipse.z = 1; ellipse.graphics.beginFill(0xFF0000); ellipse.graphics.lineStyle(2); ellipse.graphics.drawEllipse(0, 0, 60, 50); ellipse.graphics.endFill(); addChild(ellipse); ellipse.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler); ellipse.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler); } private function mouseOverHandler(e:MouseEvent):void { if(ellipse.y > 0) { ellipse.transform.matrix3D.prependTranslation(0, -10, 0); } } private function mouseOutHandler(e:MouseEvent):void { if(ellipse.y > 0) { ellipse.transform.matrix3D.prependTranslation(0, -10, 0); } else { ellipse.transform.matrix3D.prependTranslation(0, (this.stage.stageHeight - 100), 0); } } } }
appendTranslation()
prepend Prepends a matrix by multiplying the current Matrix3D object by another Matrix3D object.rhsflash.geom:Matrix3DA right-hand-side of the matrix by which the current Matrix3D is multiplied. Prepends a matrix by multiplying the current Matrix3D object by another Matrix3D object. The result combines both matrix transformations.

Matrix multiplication is different from matrix addition. Matrix multiplication is not commutative. In other words, A times B is not equal to B times A. With the prepend() method, the multiplication happens from the right side, meaning the rhs Matrix3D object is on the right side of the multiplication operator.

thisMatrix = thisMatrix ~~ rhs

The modifications made by prepend() method are object-space-relative. In other words, they are always relative to the object's initial frame of reference.

The prepend() method replaces the current matrix with the prepended matrix. If you want to prepend two matrixes without altering the current matrix, first copy the current matrix by using the clone() method and then apply the prepend() method to the copy.

append()
recompose Sets the transformation matrix's translation, rotation, and scale settings.Returns false if any of the scale elements are zero. BooleancomponentsA Vector of three Vector3D objects that replace the Matrix3D object's translation, rotation, and scale elements. orientationStyleStringeulerAnglesAn optional parameter that determines the orientation style used for the matrix transformation. The three types of orientation styles are eulerAngles (constant EULER_ANGLES), axisAngle (constant AXIS_ANGLE), and quaternion (constant QUATERNION). For additional information on the different orientation style, see the geom.Orientation3D class. Sets the transformation matrix's translation, rotation, and scale settings. Unlike the incremental changes made by the display object's rotation properties or Matrix3D object's rotation methods, the changes made by recompose() method are absolute changes. The recompose() method overwrites the matrix's transformation.

To modify the matrix's transformation with an absolute parent frame of reference, retrieve the settings with the decompose() method and make the appropriate changes. You can then set the Matrix3D object to the modified transformation using the recompose() method.

The recompose() method's parameter specifies the orientation style that was used for the transformation. The default orientation is eulerAngles, which defines the orientation with three separate angles of rotation for each axis. The rotations occur consecutively and do not change the axis of each other. The display object's axis rotation properties perform Euler Angles orientation style transformation. The other orientation style options are axisAngle and quaternion. The Axis Angle orientation uses the combination of an axis and an angle to determine the orientation. The axis around which the object is rotated is a unit vector that represents a direction. The angle represents the magnitude of the rotation about the vector. The direction also determines where a display object is facing and the angle determines which way is up. The appendRotation() and prependRotation() methods use the Axis Angle orientation. The quaternion orientation uses complex numbers and the fourth element of a vector. An orientation is represented by the three axes of rotation (x,y,z) and an angle of rotation (w). The interpolate() method uses quaternion.

flash.geom.Orientation3Ddecompose()Vector
transformVector Uses the transformation matrix to transform a Vector3D object from one space coordinate to another.A Vector3D object with the transformed coordinates. flash.geom:Vector3Dvflash.geom:Vector3DA Vector3D object holding the coordinates that are going to be transformed. Uses the transformation matrix to transform a Vector3D object from one space coordinate to another. The returned Vector3D object holds the new coordinates after the transformation. All the matrix transformations including translation are applied to the Vector3D object.

If the result of the transformVector() method was applied to the position of a display object, only the display object's position changes. The display object's rotation and scale elements remain the same.

transformVectors()deltaTransformVector()
transformVectors Uses the transformation matrix to transform a Vector of Numbers from one coordinate space to another.vinA Vector of Numbers, where every three Numbers are a 3D coordinate (x,y,z) that is going to be transformed. voutA Vector of Numbers, where every three Numbers are a 3D transformed coordinate (x,y,z). Uses the transformation matrix to transform a Vector of Numbers from one coordinate space to another. The tranformVectors() method reads every three Numbers in the vin Vector object as a 3D coordinate (x,y,z) and places a transformed 3D coordinate in the vout Vector object. All the matrix transformations including translation are applied to the vin Vector object. You can use the transformVectors() method to render and transform a 3D object as a mesh. A mesh is a collection of vertices that defines the shape of the object. transformVector()deltaTransformVector()Vectortranspose Converts the current Matrix3D object to a matrix where the rows and columns are swapped. Converts the current Matrix3D object to a matrix where the rows and columns are swapped. For example, if the current Matrix3D object's rawData contains the following 16 numbers, 1,2,3,4,11,12,13,14,21,22,23,24,31,32,33,34, the transpose() method reads every four elements as a row and turns the rows into columns. The result is a matrix with the rawData of: 1,11,21,31,2,12,22,32,3,13,23,33,4,14,24,34.

The transpose() method replaces the current matrix with a transposed matrix. If you want to transpose a matrix without altering the current matrix, first copy the current matrix by using the clone() method and then apply the transpose() method to the copy.

An orthogonal matrix is a square matrix whose transpose is equal to its inverse.

determinant A Number that determines whether a matrix is invertible.Number A Number that determines whether a matrix is invertible.

A Matrix3D object must be invertible. You can use the determinant property to make sure that a Matrix3D object is invertible. If determinant is zero, an inverse of the matrix does not exist. For example, if an entire row or column of a matrix is zero or if two rows or columns are equal, the determinant is zero. Determinant is also used to solve a series of equations.

Only a square matrix, like the Matrix3D class, has a determinant.

invert()
position A Vector3D object that holds the position, the 3D coordinate (x,y,z) of a display object within the transformation's frame of reference.flash.geom:Vector3D A Vector3D object that holds the position, the 3D coordinate (x,y,z) of a display object within the transformation's frame of reference. The position property provides immediate access to the translation vector of the display object's matrix without needing to decompose and recompose the matrix.

With the position property, you can get and set the translation elements of the transformation matrix.

appendTranslation()prependTranslation()
rawData A Vector of 16 Numbers, where every four elements can be a row or a column of a 4x4 matrix. A Vector of 16 Numbers, where every four elements can be a row or a column of a 4x4 matrix.

An exception is thrown if the rawData property is set to a matrix that is not invertible. The Matrix3D object must be invertible. If a non-invertible matrix is needed, create a subclass of the Matrix3D object.

Vector
Transform The Transform class provides access to color adjustment properties and two- or three-dimensional transformation objects that can be applied to a display object.Provides access to color as well as two and three-dimensional transformation objects and matrices that can be applied to a display object. Object The Transform class provides access to color adjustment properties and two- or three-dimensional transformation objects that can be applied to a display object. During the transformation, the color or the orientation and position of a display object is adjusted (offset) from the current values or coordinates to new values or coordinates. The Transform class also collects data about color and two-dimensional matrix transformations that are applied to a display object and all of its parent objects. You can access these combined transformations through the concatenatedColorTransform and concatenatedMatrix properties.

To apply color transformations: create a ColorTransform object, set the color adjustments using the object's methods and properties, and then assign the colorTransformation property of the transform property of the display object to the new ColorTransformation object.

To apply two-dimensional transformations: create a Matrix object, set the matrix's two-dimensional transformation, and then assign the transform.matrix property of the display object to the new Matrix object.

To apply three-dimensional transformations: start with a three-dimensional display object. A three-dimensional display object has a z property value other than zero. You do not need to create the Matrix3D object. For all three-dimensional objects, a Matrix3D object is created automatically when you assign a z value to a display object. You can access the display object's Matrix3D object through the display object's transform property. Using the methods of the Matrix3D class, you can add to or modify the existing transformation settings. Also, you can create a custom Matrix3D object, set the custom Matrix3D object's transformation elements, and then assign the new Matrix3D object to the display object using the transform.matrix property.

To modify a perspective projection of the stage or root object: use the transform.matrix property of the root display object to gain access to the PerspectiveProjection object. Or, apply different perspective projection properties to a display object by setting the perspective projection properties of the display object's parent. The child display object inherits the new properties. Specifically, create a PerspectiveProjection object and set its properties, then assign the PerspectiveProjection object to the perspectiveProjection property of the parent display object's transform property. The specified projection transformation then applies to all the display object's three-dimensional children.

Since both PerspectiveProjection and Matrix3D objects perform perspective transformations, do not assign both to a display object at the same time. Use the PerspectiveProjection object for focal length and projection center changes. For more control over the perspective transformation, create a perspective projection Matrix3D object.

The following example uses the TransformExample class to skew the bottom side of a square sprite filled with a gradient pattern. Each time the user clicks the square, the application transforms the sprite by skewing it with the following steps:
  1. The TransformExample() constructor creates a new sprite object target.
  2. The TransformExample() constructor calls the draw() method, which draws a gradient square in the sprite.
  3. The TransformExample() constructor adds a click event listener for the sprite, which is handled by the clickHandler() method.
  4. The clickHandler() method creates a new Matrix object, skewMatrix, which is set to apply a skew effect. Another matrix, tempMatrix, is assigned to the current transformation matrix of the sprite, and then is combined with skewMatrix using the concat() method. This matrix is assigned to the transform.matrix property of the square sprite. Each time the user clicks the square, the call to the clickHandler() modifies the shape of the square by skewing it.
  5. Additionally, the clickHandler() method creates a new ColorTransform object. The redOffset property of the new ColorTransform is set to the current value of redOffset and increased by 25. Likewise, the blueOffset property is reduced by 25. With each click, the colors of the sprite change.
package { import flash.display.Sprite; import flash.display.GradientType; import flash.geom.Matrix; import flash.geom.ColorTransform; import flash.events.MouseEvent; public class TransformExample extends Sprite { public function TransformExample() { var target:Sprite = new Sprite(); draw(target); addChild(target); target.useHandCursor = true; target.buttonMode = true; target.addEventListener(MouseEvent.CLICK, clickHandler) } public function draw(sprite:Sprite):void { var red:uint = 0xFF0000; var green:uint = 0x00FF00; var blue:uint = 0x0000FF; var size:Number = 100; sprite.graphics.beginGradientFill(GradientType.LINEAR, [red, blue, green], [1, 0.5, 1], [0, 200, 255]); sprite.graphics.drawRect(0, 0, 100, 100); } public function clickHandler(event:MouseEvent):void { var skewMatrix:Matrix = new Matrix(); skewMatrix.c = 0.25; var tempMatrix:Matrix = this.transform.matrix; tempMatrix.concat(skewMatrix); this.transform.matrix = tempMatrix; var rOffset:Number = this.transform.colorTransform.redOffset + 25; var bOffset:Number = this.transform.colorTransform.blueOffset - 25; this.transform.colorTransform = new ColorTransform(1, 1, 1, 1, rOffset, 0, bOffset, 0); } } }
flash.display.DisplayObject.transformflash.geom.ColorTransformflash.geom.Matrixflash.geom.Matrix3Dflash.geom.PerspectiveProjectiongetRelativeMatrix3D Returns a Matrix3D object, which can transform the space of a specified display object in relation to the current display object's space.A Matrix3D object that can be used to transform the space from the relativeTo display object to the current display object space. flash.geom:Matrix3DrelativeToflash.display:DisplayObjectThe display object relative to which the transformation occurs. To get a Matrix3D object relative to the stage, set the parameter to the root or stage object. To get the world-relative matrix of the display object, set the parameter to a display object that has a perspective transformation applied to it. Returns a Matrix3D object, which can transform the space of a specified display object in relation to the current display object's space. You can use the getRelativeMatrix3D() method to move one three-dimensional display object relative to another three-dimensional display object. flash.geom.Matrix3DcolorTransform A ColorTransform object containing values that universally adjust the colors in the display object.flash.geom:ColorTransformThe colorTransform is null when being set TypeErrorTypeError A ColorTransform object containing values that universally adjust the colors in the display object. flash.geom.ColorTransformconcatenatedColorTransform A ColorTransform object representing the combined color transformations applied to the display object and all of its parent objects, back to the root level.flash.geom:ColorTransform A ColorTransform object representing the combined color transformations applied to the display object and all of its parent objects, back to the root level. If different color transformations have been applied at different levels, all of those transformations are concatenated into one ColorTransform object for this property. flash.geom.ColorTransformconcatenatedMatrix A Matrix object representing the combined transformation matrixes of the display object and all of its parent objects, back to the root level.flash.geom:Matrix A Matrix object representing the combined transformation matrixes of the display object and all of its parent objects, back to the root level. If different transformation matrixes have been applied at different levels, all of those matrixes are concatenated into one matrix for this property. Also, for resizeable SWF content running in the browser, this property factors in the difference between stage coordinates and window coordinates due to window resizing. Thus, the property converts local coordinates to window coordinates, which may not be the same coordinate space as that of the Stage. matrix3D Provides access to the Matrix3D object of a three-dimensional display object.flash.geom:Matrix3D Provides access to the Matrix3D object of a three-dimensional display object. The Matrix3D object represents a transformation matrix that determines the display object's position and orientation. A Matrix3D object can also perform perspective projection.

If the matrix property is set to a value (not null), the matrix3D property is null. And if the matrix3D property is set to a value (not null), the matrix property is null.

flash.geom.Matrix3D
matrix A Matrix object containing values that alter the scaling, rotation, and translation of the display object.flash.geom:MatrixThe matrix is null when being set TypeErrorTypeError A Matrix object containing values that alter the scaling, rotation, and translation of the display object.

If the matrix property is set to a value (not null), the matrix3D property is null. And if the matrix3D property is set to a value (not null), the matrix property is null.

flash.geom.Matrix
perspectiveProjection Provides access to the PerspectiveProjection object of a three-dimensional display object.flash.geom:PerspectiveProjection Provides access to the PerspectiveProjection object of a three-dimensional display object. The PerspectiveProjection object can be used to modify the perspective transformation of the stage or to assign a perspective transformation to all the three-dimensional children of a display object.

Based on the field of view and aspect ratio (dimensions) of the stage, a default PerspectiveProjection object is assigned to the root object.

flash.geom.PerspectiveProjection
pixelBounds A Rectangle object that defines the bounding rectangle of the display object on the stage.flash.geom:Rectangle A Rectangle object that defines the bounding rectangle of the display object on the stage.
Matrix The Matrix class represents a transformation matrix that determines how to map points from one coordinate space to another.A standard two-dimensional homogeneous Matrix class. Object The Matrix class represents a transformation matrix that determines how to map points from one coordinate space to another. You can perform various graphical transformations on a display object by setting the properties of a Matrix object, applying that Matrix object to the matrix property of a Transform object, and then applying that Transform object as the transform property of the display object. These transformation functions include translation (x and y repositioning), rotation, scaling, and skewing.

Together these types of transformations are known as affine transformations. Affine transformations preserve the straightness of lines while transforming, so that parallel lines stay parallel.

To apply a transformation matrix to a display object, you create a Transform object, set its matrix property to the transformation matrix, and then set the transform property of the display object to the Transform object. Matrix objects are also used as parameters of some methods, such as the following:

  • The draw() method of a BitmapData object
  • The beginBitmapFill() method, beginGradientFill() method, or lineGradientStyle() method of a Graphics object

A transformation matrix object is 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. 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 transformations: translation, scaling, rotation, and skewing. You can set three of these transformations by using specialized methods, as described in the following table:

TransformationMethodMatrix valuesDisplay resultDescriptionTranslation (displacement)translate(tx, ty) Moves the image tx pixels to the right and ty pixels down.Scalingscale(sx, sy)Resizes the image, multiplying the location of each pixel by sx on the x axis and sy on the y axis.Rotationrotate(q)Rotates the image by an angle q, which is measured in radians.Skewing or shearing None; must set the properties b and cProgressively slides the image in a direction parallel to the x or y axis. The b property of the Matrix object represents the tangent of the skew angle along the y axis; the c property of the Matrix object represents the tangent of the skew angle along the x 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 display object target (by using the transform property of that display object).

Use the new Matrix() constructor to create a Matrix object before you can call the methods of the Matrix object.

The following example uses the MatrixExample class to show how a large gradient-filled square can be created. This is accomplished with the following steps:
  1. The application creates a new Matrix object myMatrix, and it uses the trace() method to output the default property values for the myMatrix object.
  2. The application calls the createGradientBox() with the width and height parameters set to 200 pixels, no rotation, and the distance to translate along the x and y axes set to 50 pixels.
  3. The application prints the myMatrix object again to show the change after calling createGradientBox().
  4. The application sets up three variables to control how the gradient box is filled:
    • colors: Sets the gradient colors to range between solid red and solid blue.
    • alphas: Sets the opacity to solid.
    • ratios: Sets the distribution of the colors to be equal for both red and blue.
  5. The application calls the graphics method beginGradientFill(), which operates on the myMatrix object, and it calls the lineTo() method, resulting in the gradient-filled box.
package { import flash.geom.Matrix; import flash.display.Sprite; import flash.display.GradientType; public class MatrixExample extends Sprite { public function MatrixExample() { var myMatrix:Matrix = new Matrix(); trace(myMatrix.toString()); // (a=1, b=0, c=0, d=1, tx=0, ty=0) myMatrix.createGradientBox(200, 200, 0, 50, 50); trace(myMatrix.toString()); // (a=0.1220703125, b=0, c=0, d=0.1220703125, tx=150, ty=150) var colors:Array = [0xFF0000, 0x0000FF]; var alphas:Array = [1, 1]; var ratios:Array = [0, 0xFF]; graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, myMatrix); graphics.lineTo(0, 300); graphics.lineTo(300, 300); graphics.lineTo(300, 0); graphics.lineTo(0, 0); } } }
flash.display.DisplayObject.transformflash.geom.Transformflash.display.BitmapData.draw()flash.display.Graphics.beginBitmapFill()flash.display.Graphics.beginGradientFill()flash.display.Graphics.lineGradientStyle()Matrix Creates a new Matrix object with the specified parameters.aNumber1The value that affects the positioning of pixels along the x axis when scaling or rotating an image. bNumber0The value that affects the positioning of pixels along the y axis when rotating or skewing an image. cNumber0The value that affects the positioning of pixels along the x axis when rotating or skewing an image. dNumber1The value that affects the positioning of pixels along the y axis when scaling or rotating an image.. txNumber0The distance by which to translate each point along the x axis. tyNumber0The distance by which to translate each point along the y axis. Creates a new two-dimensional Matrix object. Creates a new Matrix object with the specified parameters. In matrix notation, the properties are organized like this:

If you do not provide any parameters to the new Matrix() constructor, it creates an identity matrix with the following values:

a = 1
b = 0
c = 0
d = 1
tx = 0
ty = 0

In matrix notation, the identity matrix looks like this:

The following example creates matrix_1 by sending no parameters to the Matrix() constructor and matrix_2 by sending parameters to it. Notice that matrix_1, which was created with no parameters, results in an identity matrix with the values a=1, b=0, c=0, d=1, tx=0, ty=0. import flash.geom.Matrix; var matrix_1:Matrix = new Matrix(); trace(matrix_1); // (a=1, b=0, c=0, d=1, tx=0, ty=0) var matrix_2:Matrix = new Matrix(1, 2, 3, 4, 5, 6); trace(matrix_2); // (a=1, b=2, c=3, d=4, tx=5, ty=6)
clone Returns a new Matrix object that is a clone of this matrix, with an exact copy of the contained object.A Matrix object. flash.geom:MatrixReturns a new Matrix object that is a copy of the current matrix. Returns a new Matrix object that is a clone of this matrix, with an exact copy of the contained object. concat Concatenates a matrix with the current matrix, effectively combining the geometric effects of the two.mflash.geom:MatrixThe matrix to be concatenated to the source matrix. Concatenates a matrix with the current matrix, effectively combining the geometric effects of the two. In mathematical terms, concatenating two matrixes is the same as combining them using matrix multiplication.

For example, if matrix m1 scales an object by a factor of four, and matrix m2 rotates an object by 1.5707963267949 radians (Math.PI/2), then m1.concat(m2) transforms m1 into a matrix that scales an object by a factor of four and rotates the object by Math.PI/2 radians.

This method replaces the source matrix with the concatenated matrix. If you want to concatenate two matrixes without altering either of the two source matrixes, first copy the source matrix by using the clone() method, as shown in the Class Examples section.

createBox Includes parameters for scaling, rotation, and translation.scaleXNumberThe factor by which to scale horizontally. scaleYNumberThe factor by which scale vertically. rotationNumber0The amount to rotate, in radians. txNumber0The number of pixels to translate (move) to the right along the x axis. tyNumber0The number of pixels to translate (move) down along the y axis. Creates a Matrix with scaling, rotation, and translation values. Includes parameters for scaling, rotation, and translation. When applied to a matrix it sets the matrix's values based on those parameters.

Using the createBox() method lets you obtain the same matrix as you would if you applied the identity(), rotate(), scale(), and translate() methods in succession. For example, mat1.createBox(2,2,Math.PI/4, 100, 100) has the same effect as the following:

import flash.geom.Matrix; var mat1:Matrix = new Matrix(); mat1.identity(); mat1.rotate(Math.PI/4); mat1.scale(2,2); mat1.translate(10,20);
The following example sets the x scale, y scale, rotation, x location, and y location of myMatrix by calling its createBox() method. package { import flash.display.Shape; import flash.display.Sprite; import flash.geom.Matrix; import flash.geom.Transform; public class Matrix_createBox extends Sprite { public function Matrix_createBox() { var myMatrix:Matrix = new Matrix(); trace(myMatrix.toString()); // (a=1, b=0, c=0, d=1, tx=0, ty=0) myMatrix.createBox(1, 2, Math.PI/4, 50, 100); trace(myMatrix.toString()); // (a=0.7071067811865476, b=1.414213562373095, c=-0.7071067811865475, // d=1.4142135623730951, tx=100, ty=200) var rectangleShape:Shape = createRectangle(20, 80, 0xFF0000); addChild(rectangleShape); var rectangleTrans:Transform = new Transform(rectangleShape); rectangleTrans.matrix = myMatrix; } public function createRectangle(w:Number, h:Number, color:Number):Shape { var rect:Shape = new Shape(); rect.graphics.beginFill(color); rect.graphics.drawRect(0, 0, w, h); addChild(rect); return rect; } } }
flash.display.Graphics.beginBitmapFill()
createGradientBox Creates the specific style of matrix expected by the beginGradientFill() and lineGradientStyle() methods of the Graphics class.widthNumberThe width of the gradient box. heightNumberThe height of the gradient box. rotationNumber0The amount to rotate, in radians. txNumber0The distance, in pixels, to translate to the right along the x axis. This value is offset by half of the width parameter. tyNumber0The distance, in pixels, to translate down along the y axis. This value is offset by half of the height parameter. Creates the specific style of matrix expected by the beginGradientFill() method of the Graphics class. Creates the specific style of matrix expected by the beginGradientFill() and lineGradientStyle() methods of the Graphics class. Width and height are scaled to a scaleX/scaleY pair and the tx/ty values are offset by half the width and height.

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

The following illustrations show gradients in which the matrix was defined using the createGradientBox() method with different parameter settings:

createGradientBox() settingsResulting gradient
width = 25;
     height = 25; 
     rotation = 0; 
     tx = 0; 
     ty = 0;
width = 25; 
     height = 25; 
     rotation = 0; 
     tx = 25; 
     ty = 0;
width = 50; 
     height = 50; 
     rotation = 0; 
     tx = 0; 
     ty = 0;
width = 50;
     height = 50; 
     rotation = Math.PI / 4; // 45 degrees
     tx = 0; 
     ty = 0;
The following example sets the x scale, y scale, rotation, x location, and y location of myMatrix by calling its createBox() method. package { import flash.display.GradientType; import flash.display.Sprite; import flash.geom.Matrix; public class Matrix_createGradientBox extends Sprite { public function Matrix_createGradientBox() { var myMatrix:Matrix = new Matrix(); trace(myMatrix.toString()); // (a=1, b=0, c=0, d=1, tx=0, ty=0) myMatrix.createGradientBox(200, 200, 0, 50, 50); trace(myMatrix.toString()); // (a=0.1220703125, b=0, c=0, d=0.1220703125, tx=150, ty=150) var colors:Array = [0xFF0000, 0x0000FF]; var alphas:Array = [100, 100]; var ratios:Array = [0, 0xFF]; this.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, myMatrix); this.graphics.drawRect(0, 0, 300, 200); } } }
flash.display.Graphics.beginGradientFill()flash.display.Graphics.lineGradientStyle()
deltaTransformPoint Given a point in the pretransform coordinate space, returns the coordinates of that point after the transformation occurs.The point resulting from applying the matrix transformation. flash.geom:Pointpointflash.geom:PointThe point for which you want to get the result of the matrix transformation. Given a point in the pretransform coordinate space, returns the coordinates of that point after the transformation occurs. Unlike the standard transformation applied using the transformPoint() method, the deltaTransformPoint() method's transformation does not consider the translation parameters tx and ty. identity Sets each matrix property to a value that causes a null transformation. Sets each matrix property to a value that causes a null transformation. An object transformed by applying an identity matrix will be identical to the original.

After calling the identity() method, the resulting matrix has the following properties: a=1, b=0, c=0, d=1, tx=0, ty=0.

In matrix notation, the identity matrix looks like this:

invert Performs the opposite transformation of the original matrix. Performs the opposite transformation of the original matrix. You can apply an inverted matrix to an object to undo the transformation performed when applying the original matrix. The following example creates a halfScaleMatrix by calling the invert() method of doubleScaleMatrix. It then demonstrates that the two are Matrix inverses of one another -- matrices that undo any transformations performed by the other -- by creating originalAndInverseMatrix which is equal to noScaleMatrix. package { import flash.display.Shape; import flash.display.Sprite; import flash.geom.Matrix; import flash.geom.Transform; public class Matrix_invert extends Sprite { public function Matrix_invert() { var rect0:Shape = createRectangle(20, 80, 0xFF0000); var rect1:Shape = createRectangle(20, 80, 0x00FF00); var rect2:Shape = createRectangle(20, 80, 0x0000FF); var rect3:Shape = createRectangle(20, 80, 0x000000); var trans0:Transform = new Transform(rect0); var trans1:Transform = new Transform(rect1); var trans2:Transform = new Transform(rect2); var trans3:Transform = new Transform(rect3); var doubleScaleMatrix:Matrix = new Matrix(2, 0, 0, 2, 0, 0); trans0.matrix = doubleScaleMatrix; trace(doubleScaleMatrix.toString()); // (a=2, b=0, c=0, d=2, tx=0, ty=0) var noScaleMatrix:Matrix = new Matrix(1, 0, 0, 1, 0, 0); trans1.matrix = noScaleMatrix; rect1.x = 50; trace(noScaleMatrix.toString()); // (a=1, b=0, c=0, d=1, tx=0, ty=0) var halfScaleMatrix:Matrix = doubleScaleMatrix.clone(); halfScaleMatrix.invert(); trans2.matrix = halfScaleMatrix; rect2.x = 100; trace(halfScaleMatrix.toString()); // (a=0.5, b=0, c=0, d=0.5, tx=0, ty=0) var originalAndInverseMatrix:Matrix = doubleScaleMatrix.clone(); originalAndInverseMatrix.concat(halfScaleMatrix); trans3.matrix = originalAndInverseMatrix; rect3.x = 150; trace(originalAndInverseMatrix.toString()); // (a=1, b=0, c=0, d=1, tx=0, ty=0) } public function createRectangle(w:Number, h:Number, color:Number):Shape { var rect:Shape = new Shape(); rect.graphics.beginFill(color); rect.graphics.drawRect(0, 0, w, h); addChild(rect); return rect; } } } rotate Applies a rotation transformation to the Matrix object.angleNumberThe rotation angle in radians. Applies a rotation transformation to the Matrix object.

The rotate() method alters the a, b, c, and d properties of the Matrix object. In matrix notation, this is the same as concatenating the current matrix with the following:

scale Applies a scaling transformation to the matrix.sxNumberA multiplier used to scale the object along the x axis. syNumberA multiplier used to scale the object along the y axis. Applies a scaling transformation to the matrix. The x axis is multiplied by sx, and the y axis it is multiplied by sy.

The scale() method alters the a and d properties of the Matrix object. In matrix notation, this is the same as concatenating the current matrix with the following matrix:

toString Returns a text value listing the properties of the Matrix object.A string containing the values of the properties of the Matrix object: a, b, c, d, tx, and ty. StringReturns a text value listing the properties of this Matrix object. Returns a text value listing the properties of the Matrix object. transformPoint Returns the result of applying the geometric transformation represented by the Matrix object to the specified point.The point resulting from applying the Matrix transformation. flash.geom:Pointpointflash.geom:PointThe point for which you want to get the result of the Matrix transformation. Returns the result of a geometric transformation to a Point object. Returns the result of applying the geometric transformation represented by the Matrix object to the specified point. translate Translates the matrix along the x and y axes, as specified by the dx and dy parameters.dxNumberThe amount of movement along the x axis to the right, in pixels. dyNumberThe amount of movement down along the y axis, in pixels. Translates the matrix along the x and y axes.

The translate() method alters the tx and ty properties of the matrix object. In matrix notation, this is the same as concatenating the current matrix with the following:

Translates the matrix along the x and y axes, as specified by the dx and dy parameters.
a The value that affects the positioning of pixels along the x axis when scaling or rotating an image.NumberThe value that affects the positioning of pixels along the x axis when scaling or rotating an image. The value that affects the positioning of pixels along the x axis when scaling or rotating an image. The following example creates the Matrix object myMatrix and sets its a value. import flash.geom.Matrix; var myMatrix:Matrix = new Matrix(); trace(myMatrix.a); // 1 myMatrix.a = 2; trace(myMatrix.a); // 2 b The value that affects the positioning of pixels along the y axis when rotating or skewing an image.NumberThe value that affects the positioning of pixels along the y axis when rotating or skewing an image. The value that affects the positioning of pixels along the y axis when rotating or skewing an image. The following example creates the Matrix object myMatrix and sets its b value. import flash.geom.Matrix; var myMatrix:Matrix = new Matrix(); trace(myMatrix.b); // 0 var degrees:Number = 30; var radians:Number = (degrees/180) ~~ Math.PI; myMatrix.b = Math.tan(radians); trace(myMatrix.b); // 0.5773502691896257 c The value that affects the positioning of pixels along the x axis when rotating or skewing an image.NumberThe value that affects the positioning of pixels along the x axis when rotating or skewing an image. The value that affects the positioning of pixels along the x axis when rotating or skewing an image. The following example creates the Matrix object myMatrix and sets its c value. import flash.geom.Matrix; var myMatrix:Matrix = new Matrix(); trace(myMatrix.c); // 0 var degrees:Number = 30; var radians:Number = (degrees/180) ~~ Math.PI; myMatrix.c = Math.tan(radians); trace(myMatrix.c); // 0.5773502691896257 d The value that affects the positioning of pixels along the y axis when scaling or rotating an image.NumberThe value that affects the positioning of pixels along the y axis when scaling or rotating an image. The value that affects the positioning of pixels along the y axis when scaling or rotating an image. The following example creates the Matrix object myMatrix and sets its d value. import flash.geom.Matrix; var myMatrix:Matrix = new Matrix(); trace(myMatrix.d); // 1 myMatrix.d = 2; trace(myMatrix.d); // 2 tx The distance by which to translate each point along the x axis.NumberThe distance by which to translate each point along the x axis. The distance by which to translate each point along the x axis. The following example creates the Matrix object myMatrix and sets its tx value. import flash.geom.Matrix; var myMatrix:Matrix = new Matrix(); trace(myMatrix.tx); // 0 myMatrix.tx = 50; // 50 trace(myMatrix.tx); ty The distance by which to translate each point along the y axis.NumberThe distance by which to translate each point along the y axis. The distance by which to translate each point along the y axis. The following example creates the Matrix object myMatrix and sets its ty value. import flash.geom.Matrix; var myMatrix:Matrix = new Matrix(); trace(myMatrix.ty); // 0 myMatrix.ty = 50; trace(myMatrix.ty); // 50
Rectangle A Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height.A Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y), and by its width and its height. Object A Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height.

The x, y, width, and height properties of the Rectangle class are independent of each other; changing the value of one property has no effect on the others. However, the right and bottom properties are integrally related to those four properties. For example, if you change the value of the right property, the value of the width property changes; if you change the bottom property, the value of the height property changes.

The following methods and properties use Rectangle objects:

  • The applyFilter(), colorTransform(), copyChannel(), copyPixels(), draw(), fillRect(), generateFilterRect(), getColorBoundsRect(), getPixels(), merge(), paletteMap(), pixelDisolve(), setPixels(), and threshold() methods, and the rect property of the BitmapData class
  • The getBounds() and getRect() methods, and the scrollRect and scale9Grid properties of the DisplayObject class
  • The getCharBoundaries() method of the TextField class
  • The pixelBounds property of the Transform class
  • The bounds parameter for the startDrag() method of the Sprite class
  • The printArea parameter of the addPage() method of the PrintJob class

You can use the new Rectangle() constructor to create a Rectangle object.

Note: The Rectangle class does not define a rectangular Shape display object. To draw a rectangular Shape object onscreen, use the drawRect() method of the Graphics class.

The following example uses the RectangleExample class to create three new Rectangle objects at various x,y coordinates and with various heights and widths and then uses the trace() method to confirm that the Rectangle instances were successfully created. Then a Boolean variable isContained is assigned to the result of the call to the containsRect() method, which determines that the second rectangle does not fully enclose the third rectangle. package { import flash.display.Sprite; import flash.geom.Rectangle; public class RectangleExample extends Sprite { public function RectangleExample() { var firstRect:Rectangle = new Rectangle(); trace(firstRect); // (x=0, y=0, w=0, h=0) var secondRect:Rectangle = new Rectangle(1, 3, 11, 13); trace(secondRect); // (x=1, y=3, w=11, h=13) var thirdRect:Rectangle = new Rectangle(5, 8, 17, 19); trace(thirdRect); // (x=5, y=8, w=17, h=19) var isContained:Boolean = secondRect.containsRect(thirdRect); trace(isContained); // false } } }
flash.display.DisplayObject.scrollRectflash.display.BitmapDataflash.display.DisplayObjectflash.display.NativeWindowflash.text.TextField.getCharBoundaries()flash.geom.Transform.pixelBoundsflash.display.Sprite.startDrag()flash.printing.PrintJob.addPage()Rectangle Creates a new Rectangle object with the top-left corner specified by the x and y parameters and with the specified width and height parameters.xNumber0The x coordinate of the top-left corner of the rectangle. yNumber0The y coordinate of the top-left corner of the rectangle. widthNumber0The width of the rectangle, in pixels. heightNumber0The height of the rectangle, in pixels. Creates a new Rectangle object with the top-left corner specified by the x and y parameters and with the specified width and height. Creates a new Rectangle object with the top-left corner specified by the x and y parameters and with the specified width and height parameters. If you call this function without parameters, a rectangle with x, y, width, and height properties set to 0 is created. xywidthheightclone Returns a new Rectangle object with the same values for the x, y, width, and height properties as the original Rectangle object.A new Rectangle object with the same values for the x, y, width, and height properties as the original Rectangle object. flash.geom:RectangleReturns a copy of this Rectangle object. Returns a new Rectangle object with the same values for the x, y, width, and height properties as the original Rectangle object. xywidthheightcontainsPoint Determines whether the specified point is contained within the rectangular region defined by this Rectangle object.A value of true if the Rectangle object contains the specified point; otherwise false. Booleanpointflash.geom:PointThe point, as represented by its x and y coordinates. Determines if the specified point is contained within the rectangular region defined by this Rectangle object using a Point object as a parameter. Determines whether the specified point is contained within the rectangular region defined by this Rectangle object. This method is similar to the Rectangle.contains() method, except that it takes a Point object as a parameter. contains()flash.geom.PointcontainsRect Determines whether the Rectangle object specified by the rect parameter is contained within this Rectangle object.A value of true if the Rectangle object that you specify is contained by this Rectangle object; otherwise false. Booleanrectflash.geom:RectangleThe Rectangle object being checked. Determines if the Rectangle object specified by the rect parameter is contained within this Rectangle object. Determines whether the Rectangle object specified by the rect parameter is contained within this Rectangle object. A Rectangle object is said to contain another if the second Rectangle object falls entirely within the boundaries of the first. contains Determines whether the specified point is contained within the rectangular region defined by this Rectangle object.A value of true if the Rectangle object contains the specified point; otherwise false. BooleanxNumberThe x coordinate (horizontal position) of the point. yNumberThe y coordinate (vertical position) of the point. Determines if the specified point is contained within the rectangular region. Determines whether the specified point is contained within the rectangular region defined by this Rectangle object. flash.geom.Pointequals Determines whether the object specified in the toCompare parameter is equal to this Rectangle object.A value of true if the object has exactly the same values for the x, y, width, and height properties as this Rectangle object; otherwise false. BooleantoCompareflash.geom:RectangleThe rectangle to compare to this Rectangle object. Determines if the object specified in the toCompare parameter is equal to this Rectangle object. Determines whether the object specified in the toCompare parameter is equal to this Rectangle object. This method compares the x, y, width, and height properties of an object against the same properties of this Rectangle object. xywidthheightinflatePoint Increases the size of the Rectangle object.pointflash.geom:PointThe x property of this Point object is used to increase the horizontal dimension of the Rectangle object. The y property is used to increase the vertical dimension of the Rectangle object. Increases the size of the Rectangle object using a Point object as a parameter. Increases the size of the Rectangle object. This method is similar to the Rectangle.inflate() method except it takes a Point object as a parameter.

The following two code examples give the same result:

var rect1:Rectangle = new Rectangle(0,0,2,5); rect1.inflate(2,2) var rect1:Rectangle = new Rectangle(0,0,2,5); var pt1:Point = new Point(2,2); rect1.inflatePoint(pt1)
flash.geom.Point
inflate Increases the size of the Rectangle object by the specified amounts, in pixels.dxNumberThe value to be added to the left and the right of the Rectangle object. The following equation is used to calculate the new width and position of the rectangle: x -= dx; width += 2 ~~ dx; dyNumberThe value to be added to the top and the bottom of the Rectangle. The following equation is used to calculate the new height and position of the rectangle: y -= dy; height += 2 ~~ dy; Increases the size of the Rectangle object by the specified amounts, in pixels. The center point of the Rectangle object stays the same, and its size increases to the left and right by the dx value, and to the top and the bottom by the dy value. xyintersection If the Rectangle object specified in the toIntersect parameter intersects with this Rectangle object, returns the area of intersection as a Rectangle object.A Rectangle object that equals the area of intersection. If the rectangles do not intersect, this method returns an empty Rectangle object; that is, a rectangle with its x, y, width, and height properties set to 0. flash.geom:RectangletoIntersectflash.geom:RectangleThe Rectangle object to compare against to see if it intersects with this Rectangle object. Returns the area of intersection. If the Rectangle object specified in the toIntersect parameter intersects with this Rectangle object, returns the area of intersection as a Rectangle object. If the rectangles do not intersect, this method returns an empty Rectangle object with its properties set to 0.

intersects Determines whether the object specified in the toIntersect parameter intersects with this Rectangle object.A value of true if the specified object intersects with this Rectangle object; otherwise false. BooleantoIntersectflash.geom:RectangleThe Rectangle object to compare against this Rectangle object. Determines if the object specified in the toIntersect parameter intersects with this Rectangle object. Determines whether the object specified in the toIntersect parameter intersects with this Rectangle object. This method checks the x, y, width, and height properties of the specified Rectangle object to see if it intersects with this Rectangle object. xywidthheightisEmpty Determines whether or not this Rectangle object is empty.A value of true if the Rectangle object's width or height is less than or equal to 0; otherwise false. Boolean Determines whether or not this Rectangle object is empty. offsetPoint Adjusts the location of the Rectangle object using a Point object as a parameter.pointflash.geom:PointA Point object to use to offset this Rectangle object. Adjusts the location of the Rectangle object using a Point object as a parameter. Adjusts the location of the Rectangle object using a Point object as a parameter. This method is similar to the Rectangle.offset() method, except that it takes a Point object as a parameter. flash.geom.Pointoffset Adjusts the location of the Rectangle object, as determined by its top-left corner, by the specified amounts.dxNumberMoves the x value of the Rectangle object by this amount. dyNumberMoves the y value of the Rectangle object by this amount. Adjusts the location of the Rectangle object. Adjusts the location of the Rectangle object, as determined by its top-left corner, by the specified amounts. setEmpty Sets all of the Rectangle object's properties to 0.Sets all properties to 0. Sets all of the Rectangle object's properties to 0. A Rectangle object is empty if its width or height is less than or equal to 0.

This method sets the values of the x, y, width, and height properties to 0.

xywidthheight
toString Builds and returns a string that lists the horizontal and vertical positions and the width and height of the Rectangle object.A string listing the value of each of the following properties of the Rectangle object: x, y, width, and height. String Builds and returns a string that lists the horizontal and vertical positions and the width and height of the Rectangle object. xywidthheightunion Adds two rectangles together to create a new Rectangle object, by filling in the horizontal and vertical space between the two rectangles.A new Rectangle object that is the union of the two rectangles. flash.geom:RectangletoUnionflash.geom:RectangleA Rectangle object to add to this Rectangle object. Adds two rectangles together to create a new Rectangle object. Adds two rectangles together to create a new Rectangle object, by filling in the horizontal and vertical space between the two rectangles.

Note: The union() method ignores rectangles with 0 as the height or width value, such as: var rect2:Rectangle = new Rectangle(300,300,50,0);

height The height of the rectangle, in pixels.NumberThe height of the rectangle in pixels. The height of the rectangle, in pixels. Changing the height value of a Rectangle object has no effect on the x, y, and width properties.

xyheight
width The width of the rectangle, in pixels.NumberThe width of the rectangle. The width of the rectangle, in pixels. Changing the width value of a Rectangle object has no effect on the x, y, and height properties.

xyheight
x The x coordinate of the top-left corner of the rectangle.NumberThe x coordinate of the top-left corner of the rectangle. The x coordinate of the top-left corner of the rectangle. Changing the value of the x property of a Rectangle object has no effect on the y, width, and height properties.

The value of the x property is equal to the value of the left property.

left
y The y coordinate of the top-left corner of the rectangle.NumberThe y coordinate of the top-left corner. The y coordinate of the top-left corner of the rectangle. Changing the value of the y property of a Rectangle object has no effect on the x, width, and height properties.

The value of the y property is equal to the value of the top property.

xwidthheighttop
bottomRight The location of the Rectangle object's bottom-right corner, determined by the values of the right and bottom properties.flash.geom:PointThe location of the Rectangle object's bottom-right corner determined by the right and bottom properties. The location of the Rectangle object's bottom-right corner, determined by the values of the right and bottom properties.

flash.geom.Point
bottom The sum of the y and height properties.NumberThe sum of the y and height properties. The sum of the y and height properties.

yheight
left The x coordinate of the top-left corner of the rectangle.NumberThe x coordinate of the top-left corner of the rectangle. The x coordinate of the top-left corner of the rectangle. Changing the left property of a Rectangle object has no effect on the y and height properties. However it does affect the width property, whereas changing the x value does not affect the width property.

The value of the left property is equal to the value of the x property.

xywidthheight
right The sum of the x and width properties.NumberThe sum of the x and width properties. The sum of the x and width properties.

xwidth
size The size of the Rectangle object, expressed as a Point object with the values of the width and height properties.flash.geom:PointThe size of the Rectangle object, expressed as a Point object with values width, height. The size of the Rectangle object, expressed as a Point object with the values of the width and height properties. flash.geom.PointtopLeft The location of the Rectangle object's top-left corner, determined by the x and y coordinates of the point.flash.geom:PointThe location of the Rectangle object's top-left corner determined by the x and y values of the point. The location of the Rectangle object's top-left corner, determined by the x and y coordinates of the point.

flash.geom.Pointxy
top The y coordinate of the top-left corner of the rectangle.NumberThe y coordinate of the top-left corner of the rectangle. The y coordinate of the top-left corner of the rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties. However it does affect the height property, whereas changing the y value does not affect the height property.

The value of the top property is equal to the value of the y property.

xywidthheight
ColorTransform The ColorTransform class lets you adjust the color values in a display object.Object The ColorTransform class lets you adjust the color values in a display object. The color adjustment or color transformation can be applied to all four channels: red, green, blue, and alpha transparency.

When a ColorTransform object is applied to a display object, a new value for each color channel is calculated like this:

  • New red value = (old red value * redMultiplier) + redOffset
  • New green value = (old green value * greenMultiplier) + greenOffset
  • New blue value = (old blue value * blueMultiplier) + blueOffset
  • New alpha value = (old alpha value * alphaMultiplier) + alphaOffset

If any of the color channel values is greater than 255 after the calculation, it is set to 255. If it is less than 0, it is set to 0.

You can use ColorTransform objects in the following ways:

  • In the colorTransform parameter of the colorTransform() method of the BitmapData class
  • As the colorTransform property of a Transform object (which can be used as the transform property of a display object)

You must use the new ColorTransform() constructor to create a ColorTransform object before you can call the methods of the ColorTransform object.

Color transformations do not apply to the background color of a movie clip (such as a loaded SWF object). They apply only to graphics and symbols that are attached to the movie clip.

The following example uses the TransformExample class to create a simple sprite in the shape of a square filled with a gradient pattern. Each time the user clicks the square, the application transforms the colors of the square sprite, adding to the red color channel and lightening the blue color channel. This is accomplished with the following steps:
  1. The constructor creates a new sprite object target.
  2. The CustomButton() constructor calls the draw() method, which draws a gradient square in the sprite.
  3. The CustomButton() constructor adds a click event listener for the sprite, which is handled by the clickHandler() method.
  4. In the clickHandler() method, two properties are set to the redOffset and blueOffset properties of the current color transformation. Each is adjusted by 25. Then the transform.colorTransform property of the square sprite is modified to use the new offset values. Each time the user clicks the square, the call to the clickHandler() method modifies the color of the square, by augmenting its red color value and diminishing its blue color value.
package { import flash.display.Sprite; import flash.display.GradientType; import flash.geom.ColorTransform; import flash.events.MouseEvent; public class ColorTransformExample extends Sprite { public function ColorTransformExample() { var target:Sprite = new Sprite(); draw(target); addChild(target); target.useHandCursor = true; target.buttonMode = true; target.addEventListener(MouseEvent.CLICK, clickHandler) } public function draw(sprite:Sprite):void { var red:uint = 0xFF0000; var green:uint = 0x00FF00; var blue:uint = 0x0000FF; var size:Number = 100; sprite.graphics.beginGradientFill(GradientType.LINEAR, [red, blue, green], [1, 0.5, 1], [0, 200, 255]); sprite.graphics.drawRect(0, 0, 100, 100); } public function clickHandler(event:MouseEvent):void { var rOffset:Number = transform.colorTransform.redOffset + 25; var bOffset:Number = transform.colorTransform.redOffset - 25; this.transform.colorTransform = new ColorTransform(1, 1, 1, 1, rOffset, 0, bOffset, 0); } } }
flash.geom.Transformflash.display.DisplayObject.transformflash.display.BitmapData.colorTransform()ColorTransform Creates a ColorTransform object for a display object with the specified color channel values and alpha values.redMultiplierNumber1.0The value for the red multiplier, in the range from 0 to 1. greenMultiplierNumber1.0The value for the green multiplier, in the range from 0 to 1. blueMultiplierNumber1.0The value for the blue multiplier, in the range from 0 to 1. alphaMultiplierNumber1.0The value for the alpha transparency multiplier, in the range from 0 to 1. redOffsetNumber0The offset value for the red color channel, in the range from -255 to 255. greenOffsetNumber0The offset value for the green color channel, in the range from -255 to 255. blueOffsetNumber0The offset for the blue color channel value, in the range from -255 to 255. alphaOffsetNumber0The offset for alpha transparency channel value, in the range from -255 to 255. Creates a ColorTransform object for a display object. Creates a ColorTransform object for a display object with the specified color channel values and alpha values. concat Concatenates the ColorTranform object specified by the second parameter with the current ColorTransform object and sets the current object as the result, which is an additive combination of the two color transformations.secondflash.geom:ColorTransformThe ColorTransform object to be combined with the current ColorTransform object. Concatenates the ColorTranform object specified by the second parameter with the current ColorTransform object and sets the current object as the result, which is an additive combination of the two color transformations. When you apply the concatenated ColorTransform object, the effect is the same as applying the second color transformation after the original color transformation. toString Formats and returns a string that describes all of the properties of the ColorTransform object.A string that lists all of the properties of the ColorTransform object. String Formats and returns a string that describes all of the properties of the ColorTransform object. alphaMultiplier A decimal value that is multiplied with the alpha transparency channel value.Number A decimal value that is multiplied with the alpha transparency channel value.

If you set the alpha transparency value of a display object directly by using the alpha property of the DisplayObject instance, it affects the value of the alphaMultiplier property of that display object's transform.colorTransform property.

flash.display.DisplayObject.alpha
alphaOffset A number from -255 to 255 that is added to the alpha transparency channel value after it has been multiplied by the alphaMultiplier value.NumberA number from -255 to 255 that is added to the alpha transparency channel value after it has been multiplied by the alphaMultiplier value. A number from -255 to 255 that is added to the alpha transparency channel value after it has been multiplied by the alphaMultiplier value. blueMultiplier A decimal value that is multiplied with the blue channel value.Number A decimal value that is multiplied with the blue channel value. blueOffset A number from -255 to 255 that is added to the blue channel value after it has been multiplied by the blueMultiplier value.NumberA number from -255 to 255 that is added to the blue channel value after it has been multiplied by the blueMultiplier value. A number from -255 to 255 that is added to the blue channel value after it has been multiplied by the blueMultiplier value. greenMultiplier A decimal value that is multiplied with the green channel value.Number A decimal value that is multiplied with the green channel value. greenOffset A number from -255 to 255 that is added to the green channel value after it has been multiplied by the greenMultiplier value.NumberA number from -255 to 255 that is added to the green channel value after it has been multiplied by the greenMultiplier value. A number from -255 to 255 that is added to the green channel value after it has been multiplied by the greenMultiplier value. redMultiplier A decimal value that is multiplied with the red channel value.Number A decimal value that is multiplied with the red channel value. redOffset A number from -255 to 255 that is added to the red channel value after it has been multiplied by the redMultiplier value.NumberA number from -255 to 255 that is added to the red channel value after it has been multiplied by the redMultiplier value. A number from -255 to 255 that is added to the red channel value after it has been multiplied by the redMultiplier value. color The RGB color value for a ColorTransform object.uint The RGB color value for a ColorTransform object.

When you set this property, it changes the three color offset values (redOffset, greenOffset, and blueOffset) accordingly, and it sets the three color multiplier values (redMultiplier, greenMultiplier, and blueMultiplier) to 0. The alpha transparency multiplier and offset values do not change.

When you pass a value for this property, use the format 0xRRGGBB. RR, GG, and BB each consist of two hexadecimal digits that specify the offset of each color component. The 0x tells the ActionScript compiler that the number is a hexadecimal value.

Point The Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis.The Point class represents a location in a two-dimensional coordinate system. Object The Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis.

The following code creates a point at (0,0):

var myPoint:Point = new Point();

Methods and properties of the following classes use Point objects:

  • BitmapData
  • DisplayObject
  • DisplayObjectContainer
  • DisplacementMapFilter
  • NativeWindow
  • Matrix
  • Rectangle

You can use the new Point() constructor to create a Point object.

The following example uses the PointExample class to create a number of new Point objects at various x,y coordinates and then uses the trace() method to output the results of various class methods. package { import flash.display.Sprite; import flash.geom.Point; public class PointExample extends Sprite { public function PointExample() { var point1:Point = new Point(); trace(point1); // (x=0, y=0) var point2:Point = new Point(6, 8); trace(point2); // (x=6, y=8) trace(Point.interpolate(point1, point2, 0.5)); // (x=3, y=4) trace(Point.distance(point1, point2)); // 10 trace(point1.add(point2)); // (x=6, y=8) var point3:Point = point2.clone(); trace(point2.equals(point3)); // true point3.normalize(2.5); trace(point3); // (x=1.5, y=2) trace(point2.subtract(point3)); // (x=4.5, y=6) trace(point1.offset(2, 3)); // var angle:Number = Math.PI * 2 * (30 / 360); // 30 degrees trace(Point.polar(4, angle)) // (x=3.464101615137755, y=1.9999999999999998) } } }
flash.display.BitmapDataflash.display.DisplayObjectflash.display.DisplayObjectContainerflash.filters.DisplacementMapFilterflash.geom.Matrixflash.display.NativeWindowflash.geom.RectanglePoint Creates a new point.xNumber0The horizontal coordinate. yNumber0The vertical coordinate. Creates a new point. If you pass no parameters to this method, a point is created at (0,0). add Adds the coordinates of another point to the coordinates of this point to create a new point.The new point. flash.geom:Pointvflash.geom:PointThe point to be added. Adds the coordinates of another point to the coordinates of this point to create a new point. clone Creates a copy of this Point object.The new Point object. flash.geom:PointCreates a copy of the Point object. Creates a copy of this Point object. distance Returns the distance between pt1 and pt2.The distance between the first and second points. Numberpt1flash.geom:PointThe first point. pt2flash.geom:PointThe second point. Returns the distance between pt1 and pt2. equals Determines whether two points are equal.A value of true if the object is equal to this Point object; false if it is not equal. BooleantoCompareflash.geom:PointThe point to be compared. Determines whether two points are equal. Two points are equal if they have the same x and y values. interpolate Determines a point between two specified points.The new, interpolated point. flash.geom:Pointpt1flash.geom:PointThe first point. pt2flash.geom:PointThe second point. fNumberThe level of interpolation between the two points. Indicates where the new point will be, along the line between pt1 and pt2. If f=1, pt1 is returned; if f=0, pt2 is returned. Determines a point between two specified points. The parameter f determines where the new interpolated point is located relative to the two end points specified by parameters pt1 and pt2. The closer the value of the parameter f is to 1.0, the closer the interpolated point is to the first point (parameter pt1). The closer the value of the parameter f is to 0, the closer the interpolated point is to the second point (parameter pt2). normalize Scales the line segment between (0,0) and the current point to a set length.The normalized point. thicknessNumberThe scaling value. For example, if the current point is (0,5), and you normalize it to 1, the point returned is at (0,1). Scales the line segment between (0,0) and the current point to a set length. lengthoffset Offsets the Point object by the specified amount.dxNumberThe amount by which to offset the horizontal coordinate, x. dyNumberThe amount by which to offset the vertical coordinate, y. Offsets the Point object by the specified amount. The value of dx is added to the original value of x to create the new x value. The value of dy is added to the original value of y to create the new y value. polar Converts a pair of polar coordinates to a Cartesian point coordinate.The Cartesian point. flash.geom:PointlenNumberThe length coordinate of the polar pair. angleNumberThe angle, in radians, of the polar pair. Converts a pair of polar coordinates to a Cartesian point coordinate. lengthMath.round()subtract Subtracts the coordinates of another point from the coordinates of this point to create a new point.The new point. flash.geom:Pointvflash.geom:PointThe point to be subtracted. Subtracts the coordinates of another point from the coordinates of this point to create a new point. toString Returns a string that contains the values of the x and y coordinates.The string representation of the coordinates. StringReturns a string that contains the values of the x and y coordinates. Returns a string that contains the values of the x and y coordinates. The string has the form "(x=x, y=y)", so calling the toString() method for a point at 23,17 would return "(x=23, y=17)". x The horizontal coordinate of the point.Number The horizontal coordinate of the point. The default value is 0. y The vertical coordinate of the point.Number The vertical coordinate of the point. The default value is 0. length The length of the line segment from (0,0) to this point.Number The length of the line segment from (0,0) to this point. Point.polar()
Orientation3D The Orientation3D class is an enumeration of constant values for representing the orientation style of a Matrix3D object.Object The Orientation3D class is an enumeration of constant values for representing the orientation style of a Matrix3D object. The three types of orientation are Euler angles, axis angle, and quaternion. The decompose and recompose methods of the Matrix3D object take one of these enumerated types to identify the rotational components of the Matrix. flash.geom.Matrix3Dflash.geom.Transformflash.geom.PerspectiveProjectionAXIS_ANGLE The axis angle orientation uses a combination of an axis and an angle to determine the orientation.axisAngleString The axis angle orientation uses a combination of an axis and an angle to determine the orientation. A line or vector from the center of a three-dimensional globe to the surface is an example of an axis. The axis around which the object is rotated is a unit vector that represents any possible direction in the three-dimensional space. The angle represents the magnitude of the rotation about the vector. The direction determines where a display object is facing and the roll angle determines which way is up. You can use Vector3D and the Matrix3D objects to determine the various matrix transformations as well as to determine important three-dimensional programming values such as the distance to the intersection of two objects that can be used to detect simple collision between three-dimensional objects.

The Matrix3D.appendRotation() and Matrix3D.prependRotation() methods use the axis angle orientation.

flash.geom.Matrix3D.decompose()flash.geom.Matrix3D.recompose()
EULER_ANGLES Euler angles, the default orientation for decompose() and recompose() methods, defines the orientation with three separate angles of rotation for each axis.eulerAnglesStringDefines the orientation with three separate angles of rotation for each axis. Euler angles, the default orientation for decompose() and recompose() methods, defines the orientation with three separate angles of rotation for each axis. Usually, a rotation around the x axis is followed by a rotation around the y axis, which is followed by a rotation around the z axis.

Euler angles can sometimes lead to animation errors because of problems such as singularities when rotating around the x axis or gimbal lock. For example, since with Euler angles each axis is handled independently, gimbal lock can occur during the rotation around two or more axes. The axes can become aligned, leading to unexpected results.

The axis rotation properties of the display object perform Euler angles rotation.

flash.geom.Matrix3D.decompose()flash.geom.Matrix3D.recompose()
QUATERNION The quaternion orientation uses complex numbers.quaternionStringAn orientation in quaternion uses the three axes (x,y,z) and an angle of rotation (w). The quaternion orientation uses complex numbers. An orientation in quaternion is by the three axes of rotation (x,y,z) and an angle of rotation (w). Quaternion guarantees the shortest, most efficient path for the rotation. It also produces a smooth, gimbal-lock-free rotation. A gimbal lock can occur when during the rotation around two or more axes the axes are aligned, leading to unexpected results.

The Matrix3D.interpolate() method uses quaternion.

flash.geom.Matrix3D.decompose()flash.geom.Matrix3D.recompose()
PerspectiveProjection The PerspectiveProjection class provides an easy way to assign or modify the perspective transformations of a display object and all of its children.Object The PerspectiveProjection class provides an easy way to assign or modify the perspective transformations of a display object and all of its children. For more complex or custom perspective transformations, use the Matrix3D class. While the PerspectiveProjection class provides basic three-dimensional presentation properties, the Matrix3D class provides more detailed control over the three-dimensional presentation of display objects.

Projection is a way of representing a three-dimensional object in a two-dimensional space, like a cube projected onto a computer screen. Perspective projection uses a viewing frustum (a rectangular pyramid) to model and project a three-dimensional world and its objects on the screen. The viewing frustum becomes increasingly wider as it moves further from the origin of the viewpoint. The origin of the viewpoint could be a camera or the eyes of an observer facing the screen. The projected perspective produces the illusion of three dimensions with depth and distance, where the objects closer to the screen appear larger than the objects farther from the screen.

A default PerspectiveProjection object is a framework defined for perspective transformation of the root object, based on the field of view and aspect ratio (dimensions) of the stage. The projection center, the vanishing point, is set to the center of the stage, which means the three-dimensional display objects disappear toward the center of the stage as they move back in the z axis. The default viewpoint is at point (0,0) looking down the positive z axis. The y-axis points down toward the bottom of the screen. You can gain access to the root display object's perspective projection settings and change the field of view and projection center properties of the perspectiveProjection property through the root object's DisplayObject.transform property.

You can also set a different perspective projection setting for a display object through the parent's perspective projection. First, create a PerspectiveProjection object and set its fieldOfView and projectionCenter properties. Next, assign the PerspectiveProjection object to the parent display object using the DisplayObject.transform property. The specified projection matrix and transformation will then apply to all the display object's three-dimensional children.

flash.display.DisplayObject.transformflash.geom.Transformflash.geom.Matrix3Dflash.geom.Utils3DPerspectiveProjection Creates an instance of a PerspectiveProjection object. Creates an instance of a PerspectiveProjection object. toMatrix3D Returns the underlying Matrix3D object of the display object.The underlying Matrix3D object. flash.geom:Matrix3D Returns the underlying Matrix3D object of the display object.

A display object, like the root object, can have a PerspectiveProjection object without needing a Matrix3D property defined for its transformations. In fact, use either a PerspectiveProjection or a Matrix3D object to specify the perspective transformation. If when using the PerspectiveProjection object, a Matrix3D object was needed, the toMatrix3D() method can retrieve the underlying Matrix3D object of the display object. For example, the toMatrix3D() method can be used with the Utils3D.projectVectors() method.

flash.geom.Matrix3D
fieldOfView Specifies an angle, as a degree between 0 and 180, for the field of view in three dimensions.NumberSpecifies an angle, as a degree between 0 and 180, for the field of view in three dimensions. Specifies an angle, as a degree between 0 and 180, for the field of view in three dimensions. This value determines how strong the perspective transformation and distortion apply to a three-dimensional display object with a non-zero z-coordinate.

A degree close to 0 means that the screen's two-dimensional x- and y-coordinates are roughly the same as the three-dimensional x-, y-, and z-coordinates with little or no distortion. In other words, for a small angle, a display object moving down the z axis appears to stay near the same size and moves little.

A value close to 180 degrees results in a fisheye lens effect: positions with a z value smaller than 0 are magnified, while positions with a z value larger than 0 are minimized. With a large angle, a display object moving down the z axis appears to change size quickly and moves a great distance. If the field of view is set to 0 or 180, nothing is seen on the screen.

focalLength The distance between the eye or the viewpoint's origin (0,0,0) and the display object located in the z axis.Number The distance between the eye or the viewpoint's origin (0,0,0) and the display object located in the z axis. During the perspective transformation, the focalLength is calculated dynamically using the angle of the field of view and the stage's aspect ratio (stage width divided by stage height). fieldOfViewprojectionCenter A two-dimensional point representing the center of the projection, the vanishing point for the display object.flash.geom:Point A two-dimensional point representing the center of the projection, the vanishing point for the display object.

The projectionCenter property is an offset to the default registration point that is the upper left of the stage, point (0,0). The default projection transformation center is in the middle of the stage, which means the three-dimensional display objects disappear toward the center of the stage as they move backwards in the z axis.