The Matrix ClassThe Matrix class allows you to perform a transformation by manipulating coordinates. It is important when using this class to import it first at the beginning of your script, like this: import flash.geom.Matrix; To instantiate a new instance of the Matrix class, use this code as a template: var myMatrix:Matrix = new Matrix(a,b,c,d,tx,ty);
Example: This example will create an instance of the Matrix class and send it to the Output panel: import flash.geom.Matrix; var myMatrix:Matrix = new Matrix(1,2,3,4,5,6); trace(myMatrix); //output: (a=1, b=2, c=3, d=4, tx=5, ty=6) Because all the properties of this object match the parameters identically, they will be skipped. MethodscloneAvailability: FP:8, AS:1.0 Generic Template: myMatrix.clone(); Returns: Matrix This method will return an exact duplicate of the Matrix object it is being called on. Description: This method will create an exact copy of the Matrix object it is being called on. Example: This example will create a Matrix object, create a copy, and output that copy: import flash.geom.Matrix; var myMatrix:Matrix = new Matrix(1,2,3,4,5,6); var myMatrix2:Matrix = myMatrix.clone(); trace(myMatrix2); //output: (a=1, b=2, c=3, d=4, tx=5, ty=6) concatAvailability: FP:8, AS:1.0 Generic Template: myMatrix.concat(matrix); Parameters:
Description: This method will combine one matrix with another. This may seem like the values will be added, but instead a matrix multiplication will occur. Example: This example will create two Matrix objects and combine them: import flash.geom.Matrix; var myMatrix:Matrix = new Matrix(1,2,3,4,5,6); var myMatrix2:Matrix = myMatrix.clone(); myMatrix.concat(myMatrix2); trace(myMatrix); //output: (a=7, b=10, c=15, d=22, tx=28, ty=40) createBoxAvailability: FP:8, AS:1.0 Generic Template: myMatrix.createBox(scaleX, scaleY, rot, x, y); Parameters:
Description: This method will transform the matrix values based on given information such as scaling and rotation. This one method will accomplish in a single task what it would take several other of the Matrix methods to accomplish in a row. Example: This example will create a Matrix object, use the createBox method to transform it, and then output the results:
createGradientMatrixAvailability: FP:8, AS:1.0 Generic Template: myMatrix.createGradientMatrix(w, h, rot, x, y); Parameters:
Description: This method will create a very specific type of matrix, the gradient matrix. Example: This example will use the createGradientMatrix method to create the gradient for a square that will be drawn with the drawing API: import flash.geom.Matrix; //create the arrays we need var colors:Array = [0x397dce, 0x000033]; var alphas:Array = [75, 100]; var ratios:Array = [0, 255]; //create the matrix var myMatrix:Matrix = new Matrix(); //create the gradient myMatrix.createGradientBox(200, 200, 0, 50, 50); //draw the square this.beginGradientFill("linear", colors, alphas, ratios, myMatrix); this.lineTo(0, 300); this.lineTo(300, 300); this.lineTo(300, 0); this.lineTo(0, 0); this.endFill(); deltaTransformPointAvailability: FP:8, AS:1.0 Generic Template: myMatrix.deltaTransformPoint(point); Parameters:
Returns: Point A new Point object. Description: This method will create a new Point object based on the transformation. This method differs from the transformPoint method in that it does not use tx or ty when the transformation occurs. Example: This example will use the deltaTransformPoint to transform a point from one coordinate to another: import flash.geom.Matrix; import flash.geom.Point; //create the point var point:Point = new Point(25, 15); //create the matrix var myMatrix:Matrix = new Matrix(1,2,3,4,5,6); //trace the point after delta transformation trace(myMatrix.deltaTransformPoint(point)); //output: (x=70, y=110) identityAvailability: FP:8, AS:1.0 Generic Template: myMatrix.identity(); Description: This method will cause the matrix calling it to revert back to a default matrix. Example: This example will create a defined matrix and send its information to the Output panel. Then it will call the identity method and send the information again: import flash.geom.Matrix; var myMatrix:Matrix = new Matrix(4,5,6,7,8,9); trace(myMatrix); myMatrix.identity(); trace(myMatrix); //output:(a=4, b=5, c=6, d=7, tx=8, ty=9) //(a=1, b=0, c=0, d=1, tx=0, ty=0) invertAvailability: FP:8, AS:1.0 Generic Template: myMatrix.invert(); Description: This method will completely reverse the matrix if, for instance, you want to undo a transformation. Example: This example will create a defined matrix and send its information to the Output panel. Then it will call the invert method and send the information again: import flash.geom.Matrix; var myMatrix:Matrix = new Matrix(1,2,3,4,5,6); trace(myMatrix); myMatrix.invert(); trace(myMatrix); //output:(a=1, b=2, c=3, d=4, tx=5, ty=6) //(a=-2, b=1, c=1.5, d=-0.5, tx=1, ty=-2) rotateAvailability: FP:8, AS:1.0 Generic Template: myMatrix.rotate(rot); Parameters:
Description: This method will alter the a and d properties of the matrix so it can be used to apply rotation. Example: This example will create a defined matrix and send its information to the Output panel. Then it will be rotated 45 degrees and sent back to the Output panel:
scaleAvailability: FP:8, AS:1.0 Generic Template: myMatrix.scale(x,y); Parameters:
Description: This method will alter the a and d properties of the matrix so it can be used to apply scaling. Example: This example will create a defined matrix and send its information to the Output panel. Then it will be scaled and sent back to the Output panel: import flash.geom.Matrix; var myMatrix:Matrix = new Matrix(); trace(myMatrix); myMatrix.scale(2,2); trace(myMatrix); //output:(a=1, b=0, c=0, d=1, tx=0, ty=0) //(a=2, b=0, c=0, d=2, tx=0, ty=0) toStringAvailability: FP:8, AS:1.0 Generic Template: myMatrix.toString(); Returns: String The string will contain all the properties of the matrix. Description: This method will return a string with every property of the matrix fully defined. Example: This example will create a defined matrix and send the output of the toString method to the Output panel: import flash.geom.Matrix; var myMatrix:Matrix = new Matrix(); trace(myMatrix.toString()); //output:(a=1, b=0, c=0, d=1, tx=0, ty=0) TRansformPointAvailability: FP:8, AS:1.0 Generic Template: myMatrix.transformPoint(point); Parameters:
Returns: Point A new Point object. Description: This method will apply a transformation on the defined point based on the given matrix. Example: This example will create a Point at (10,10) and run it with the matrix using the TRansformPoint method: import flash.geom.Matrix; import flash.geom.Point; var point:Point = new Point(10,10); var myMatrix:Matrix = new Matrix(1,1,1,1,1,1); trace(myMatrix.transformPoint(point)); //output:(x=21, y=21) translateAvailability: FP:8, AS:1.0 Generic Template: myMatrix.translate(x,y); Parameters:
Description: This method will modify a matrix by adjusting it along the horizontal and vertical axes. Example: This example will create a default matrix and adjust it by (10,10): import flash.geom.Matrix; var myMatrix:Matrix = new Matrix(); trace(myMatrix); myMatrix.translate(10,10); trace(myMatrix); //output:(a=1, b=0, c=0, d=1, tx=0, ty=0) //(a=1, b=0, c=0, d=1, tx=10, ty=10) |