This Animate Flash ActionScript tutorial of Matrix Transformation shows how to create an interesting flash rotation animation by Matrix Transformation.

You can create flash rotation animation very easily with Matrix Transformation. This flash actionscript tutorial show you how to do it.

Animate 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)

*/


//Create a Timer object and store it in a variable called myClock.
//The timer will trigger every 100 milliseconds (0.1 seconds)
//1000 milliseconds = 1 second
//The repeatCount is 0, i.e. timer will trigger infinity
//Summary:
//Create a Timer instance that will trigger every 0.1 seconds infinity
var myClock:Timer = new Timer(100, 0);

 

//Timer object created will not start automatically
//You have to start it
myClock.start();

 

//Add an event listener to the timer object (myClock)
//The event that listen is called TIMER which will be trigger every 0.1 seconds
//Every time the TIMER event is triggered, it will call the countingClock function
myClock.addEventListener(TimerEvent.TIMER, rotateSun);

 

//You can set the rotateSpeed as variable
//A smaller number (e.g. 4) rotate a greater angle
//A higher number (e.g. 360) rotate a smaller angle (smoother rotation)
var rotateAngle:Number = 360;

 

var wishMatrix:Matrix = new Matrix;

function rotateSun (evt:TimerEvent):void {
//Position the MovieClip to location
//By default the location of MovieClip is (0, 0)
//See Identity Matrix
wishMatrix.tx = 256;
wishMatrix.ty = 190;

//Use rotate method to rotate the matrix
//Note that rotate method will affext the:
//x-scale(a), y-skew(b), x-skew (c) and y-scale(d)
//The speed of rotation is control
wishMatrix.rotate( Math.PI/rotateAngle );

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

}

Download Source File:

transformation-matrix-7.fla