Flash AS3 Tutorials Center | Interesting Flash Animation Tutorials | Valuing Flash Animation Tutorials | Flash ActionScript and Animation Home

AS3 Beginner Tutorials | AS3 Basic Lessons | AS3 Valuing Courses | AS3 Components Tutorials | AS3 and PHP Interaction Tutorials
AS3 Practical Tutorials | AS3 Animation Techniques | AS3 Transition Effects Tutorials | AS3 Download Upload Files | AS3 Particle Systems
Communication Between Flash Movies with AS3 | AS3 and JavaScript interaction | AS3 Matrix Transformation | AS3 Physics Simulation Tutorials

Flash ActionScript: Reset Matrix Transformation

This Flash ActionScript tutorial of Matrix Transformation shows how to reset Matrix Transformation. To reset Matrix Transformation simply means to set it back to Identity Matrix.

Please update flash player to view this Flash ActionScript tutorial!

Flash Tutorial Content:

You can reset Matrix Transformation after doing some transformation. To reset Matrix Transformation simply means to set the Matrix back to Identity Matrix.

The complete Flash Movie is shown as above, you may try how it works before you start this tutorial.

Flash ActionScript Codes:

//import this class if used in custom class
//import flash.geom.Matrix;

 

/*
Some information of Matrix:

A matrix is used to store datas used in calculation.
The calculation can be used in the following classes:
- flash.geom.Matrix,
- flash.filters.ColorMatrixFilter
- flash.filters.ConvolutionFilter.

Here's an example of a 3 x 3 matrix. Each value (e.g.
a, b, c, d, e, f, g, h, i) is used in calculation.

a, b, c,
d, e, f
g, h, i

This is Matrix with no any effect:
(This is called Identity Matrix)

1, 0, 0
0, 1, 0
0, 0, 1

For Transformation Matrix, each value of the matrix
that serve specific calculation as shown below:

x-scale, y-skew, 0
x-skew, y-scale, 0
x-position, y-position, 1

For example:
x-scale is used to scale a MovieClip in x-axis,
Note: A value of 1 means 100% of scale.
x-position is used to set the x-axis location of a MovieClip
x-skew is used to skew a MovieClip in x-axis
Note:
A value of 0 means no skew, while
A value of 1 means a skew with an amount equal to the width or
height of a MovieClip.

For Transformation Matrix, it only uses a 2 x 3 Matrix
as shown below because other will use default values.

x-scale (a), y-skew (b),
x-skew (c), y-scale (d),
x-position (tx), y-position (ty)

*/


//Hide the reset button at beginning
reset_btn.visible = false;

//Declare a new Matrix that use for Matrix Transformation
var wishMatrix:Matrix = new Matrix;


/*
Create a new Matrix for the transformation.
The Matrix is as below:

x-scale (2), y-skew (0),
x-skew (0.5), y-scale (1),
x-position (200), y-position (150)

Explanation:
x-scale equal 2 means scale MovieClip 200% along x-axis
y-skew equal 0 means no skew along y-axis
x-skew equal 0.5 means skew along x-axis (0.5 width of object)
y-scale equal 1 means scale MovieClip 100% along y-axis
x-position equal 200 means move MovieClip to x-200
y-position equal 150 means move MovieClip to y-150
*/

function transformSquare (evt:Event):void {

/*
Add values to the new Matrix.
Remember that:

x-scale (a), y-skew (b),
x-skew (c), y-scale (d),
x-position (tx), y-position (ty)

The Matrix is now:

x-scale (2), y-skew (0),
x-skew (0.5), y-scale (1),
x-position (200), y-position (150)

Explanation:
x-scale equal 2 means scale MovieClip 200% along x-axis
y-skew equal 0 means no skew along y-axis
x-skew equal 0.5 means skew along x-axis (0.5 width of object)
y-scale equal 1 means scale MovieClip 100% along y-axis
x-position equal 200 means move MovieClip to x-200
y-position equal 150 means move MovieClip to y-150
*/
wishMatrix.a = 2;
wishMatrix.b = 0;
wishMatrix.c = 0.5;
wishMatrix.d = 1;
wishMatrix.tx = 200;
wishMatrix.ty = 150;

//Set the Transform.matrix value of the MovieClip (square_mc)
//to the new Matrix
square_mc.transform.matrix = wishMatrix;

//Un-hide the reset button at beginning
reset_btn.visible = true;

}

transform_btn.addEventListener(MouseEvent.CLICK, transformSquare);

function resetToIdentity (evt:Event):void {

/*
Set the Matrix to an identity Matrix
identity Matrix = without any transformation:
i.e.
x-scale (1), y-skew (0),
x-skew (0), y-scale (1),
x-position (0), y-position (0)

This method is useful if you wish to reset a MovieClip
after some transformation.
*/
wishMatrix.identity();

//Keep the ovieClip in same loc
//Without this setting, the MovieClip will go to (0,0) co-ordinate
wishMatrix.tx = 200;
wishMatrix.ty = 150;

//Apply the new transformation
square_mc.transform.matrix = wishMatrix;

}

reset_btn.addEventListener(MouseEvent.CLICK, resetToIdentity);

Download Flash Source File:

Flash Source File transformation-matrix-6.fla

Remarks:

This Flash ActionScript Matrix Transformation tutorial shows how to reset Matrix Transformation.