Flash Tutorial: Making 3D Rotation animation effect

Source: Internet
Author: User
Tags addchild event listener

This tutorial focuses on code writing, version as 3.0. As long as the production of a rotating 3D ball, the production of graphics components do not explain, please refer to the tutorial.

Include "Math2.as"

Picture container

var menu:sprite=new Sprite ();

Make an icon move

menu.x = 300;

MENU.Y = 200;

Registering event Listeners

Menu.addeventlistener (Event.enter_frame,movemenu);

This.addchild (menu);

The Intercept of the ellipse on the X and Y axes

var disx:number = 200;

var disy:number = 10;

Rotational speed

var speed:number = 0;

Initmenu (5);

function Initmenu (n:int) {

for (Var i:int i

var mc:movieclip = new Iconmenu ();

Zoom Out icon

Mc.scalex = Mc.scaley =. 5;

Menu.addchild (MC);

}

}

Event Listener Functions

function Movemenu (e:event): void {

Get Number of icons

var iconcount:int = Menu.numchildren;

Defining arrays

var deptharray:array = new Array ();

Split the 360 degrees.

var angle:number = 360/iconcount;

for (var z:int; z

Get icon based on depth

var mc:movieclip = Menu.getchildat (z);

Jump to different frames to display a different icon

Mc.gotoandstop (z+1);

Set the location of the icon

mc.x = cosd (speed + angle*z) * DISX;

MC.Y = SinD (speed + angle*z) * DISY;

SetProp (MC, "Alpha");

SetProp (MC, "ScaleX",. 2,.7);

SetProp (MC, "ScaleY",. 2,.7);

Save icon to array

DEPTHARRAY[Z] = MC;

}

To reset the depth of an icon

Arrange (Deptharray);

Speed + 2;

}

function Arrange (Deptharray:array): void {

Sort by y-coordinate

Deptharray.sorton ("Y", array.numeric);

var i:int = deptharray.length;

while (i--) {

Menu.setchildindex (Deptharray[i], i);

}

}

function SetProp (Mc:movieclip,prop:string,n1:number =. 5, N2:number = 1): void {

Mc[prop] = ((mc.y + 2 * disy)/disy-1)/2 * (N2-N1) + N1;

}

5, new. As document, save name: Math2.as (this document is for trigonometric function calculation)

Angle Turn radians

function Angletoradian (angle:number): number

{

Return angle* (math.pi/180);

}

radians Turn angle

function Radiantoangle (radian:number): number

{

Return radian* (180/MATH.PI);

}

To calculate a sine value

function SinD (angle:number): number

{

Return Math.sin (Angletoradian (angle));

}

To calculate the cosine value

function Cosd (angle:number): number

{

Return Math.Cos (Angletoradian (angle));

}

Calculate anyway Tangent

function atan2d (Y:number, X:number): number

{

Return Radiantoangle (math.atan2 (y, x));

}

Save the FLA document in the same directory as the math2.as document and test it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.