Pages

Friday, February 10, 2012

Rotation of the object shape

At this time I'll share a bit of flash tutorial ActionScript 3 to create an object and provide round the object using ActionScript 3.0. Here are the steps.
Create a new Flash file, change the Stage size to 650 x 560, give the Stage with gray color and the FPS = 24.00.



We do not need to create objects on the Stage, simply by using ActionScript to create objects and to provide more spin on the object.
Open the action panel (F9) and write the following script to create objects in the blue box.

var blue:Shape=new Shape();
this.addChild(blue);
blue.x=140;
blue.y=200;
drawShapes();
var blueMat:Matrix=blue.transform.matrix.clone();
function drawShapes():void {
blue.graphics.lineStyle();
blue.graphics.beginFill(0×000066);
blue.graphics.drawRect(-60,-60,120,120);
blue.graphics.endFill();
blue.graphics.beginFill(0xCC0000);
blue.graphics.endFill();
blue.graphics.lineStyle(2,0xFFFF00);
blue.graphics.moveTo(-5,0);
blue.graphics.lineTo(5,0);
blue.graphics.moveTo(0,-5);
blue.graphics.lineTo(0,5);
}

Press Ctrl + Enter to see the result of making a blue box with the ActionScript object.


Open the Action panel again, then add the following script to create the purple box is smaller than the blue box.

var purple:Shape=new Shape();
this.addChild(purple);
purple.x=500;
purple.y=190;
drawShapespurple();
var purpleMat:Matrix=purple.transform.matrix.clone();
function drawShapespurple():void {
purple.graphics.lineStyle();
purple.graphics.beginFill(0×660066);
purple.graphics.drawRect(0,0,60,60);
purple.graphics.endFill();
purple.graphics.lineStyle(2,0xFFFF00);
purple.graphics.moveTo(-5,0);
purple.graphics.lineTo(5,0);
purple.graphics.moveTo(0,-5);
purple.graphics.lineTo(0,5);
this.graphics.lineStyle();
this.graphics.beginFill(0xCC0000);
this.graphics.endFill();
}

Press Ctrl + Enter to see the results.


Next we will create a script to provide a second round of the object. Open the Action panel again and Add the following script to make the second round of the object.

import fl.motion.MatrixTransformer;
var curPurpleAng:Number=0;
var curBlueAng:Number=0;
var blueRotCenter:Point=new Point(30,30);
var purpleRotCenter:Point=new Point(450,220);
function rotateBlue(deg:Number):void {
var mat:Matrix=blueMat.clone();
MatrixTransformer.rotateAroundInternalPoint(mat,blueRotCenter.x,blueRotCenter.y,deg);
blue.transform.matrix=mat;
}
function rotatePurple(deg:Number):void {
var mat:Matrix=purpleMat.clone();
MatrixTransformer.rotateAroundExternalPoint(mat,purpleRotCenter.x,purpleRotCenter.y,deg);
purple.transform.matrix=mat;
}
this.addEventListener(Event.ENTER_FRAME,onEnter);
function onEnter(e:Event):void {
curPurpleAng=(curPurpleAng+2)%360;
rotatePurple(curPurpleAng);
curBlueAng=(curBlueAng-2)%360;
rotateBlue(curBlueAng);
}

Press Ctrl + Enter to see the results. Save your work.


No comments:

Post a Comment