# A beautiful bubble animation tutorial in FlashCS4

Source: Internet
Author: User
Tags numeric

FlashCS4 in the production of beautiful bubble animation, is an examination of the test, this article on the FlashCS4 in the production of beautiful bubble animation tutorial specifically elaborated for reading. Please read the following carefully!

Detailed code:

function Ball (R:int): MovieClip {//Custom function ball, parameter R, integer type, return value is MovieClip

var col:uint=0xffffff*math.random ()//declares an unsigned integer variable col to get any color

var sh:movieclip=new MovieClip ()//Declare a movie clip class instance sh

Sh.graphics.drawCircle (0,0,r)//Draw circle in SH (center coordinate (0,0), radius is parameter R)

Sh.graphics.endFill ()//End Fill

return sh;//SH

}

Var ballarr:array=[];//declares an empty array Ballarr

for (var i:int=0 i<10; i++) {//Create a For loop, loop 10 times

var balls:movieclip=ball (Math.random () *20+20)//Declaring a movie clip class instance balls, calling function ball (the random value of the parameter R radius value is 20-40)

x coordinate of Balls.x=math.random () * (stage.stagewidth-balls.width) +balls.width/2;//balls

Balls.y=math.random () * (stage.stageheight-balls.height) +balls.height/2;//balls y-coordinate, which appears anywhere on the stage

Balls.vx=math.random () *2-1;//set custom properties for balls VX, a number of random numbers between 1-1, indicating the velocity in the X direction

Balls.vy=math.random () *2-1;//sets the custom attribute VY for balls, which is a random number between 1-1, indicating the speed of the Y direction

Ballarr.push (balls)//Add balls to array Ballarr

}

function Frame (e) {//define Frame frequency event function frame

for (Var i:int=0 i

var balls:movieclip=ballarr[i];//declares a movie clip class instance balls, gets the elements of the array Ballarr

The x-coordinate of balls.x+=balls.vx;//balls increases each frame BALLS.VX

The y-coordinate of the balls.y+=balls.vy;//balls increases each frame Balls.vy

if (balls.x

Balls.x=balls.width/2;//balls's x coordinates get half the balls width

BALLS.VX*=-1;//BALLS.VX to get its opposite number

}

if (BALLS.X>STAGE.STAGEWIDTH-BALLS.WIDTH/2) {//If alls out of the right edge of the stage

Balls.x=stage.stagewidth-balls.width/2;//balls's X coordinate gets the difference between the scene width and the balls width half

BALLS.VX*=-1;//BALLS.VX to get its opposite number

}

if (balls.y

Balls.y=balls.height/2;//balls's y-coordinate gets half the balls height.

Balls.vy*=-1;//balls.vy to get its opposite number

}

if (BALLS.Y>STAGE.STAGEHEIGHT-BALLS.HEIGHT/2) {//If balls out of the stage below the edge

Balls.y=stage.stageheight-balls.height/2;//balls y coordinates to get the difference between the stage height and the balls height half

Balls.vy*=-1;//balls.vy to get its opposite number

}

}

For (Var j:int=0 j

var ball0:movieclip=ballarr[j];//declares a movie clip class instance ball0, gets the elements of the array Ballarr

For (Var m:int=j+1 m

var ball1:movieclip=ballarr[m];//declares a movie clip class instance ball1, gets the elements of the array Ballarr

Var dx:number=ball1.x-ball0.x;//declares a numeric variable dx, obtaining

Var dy:number=ball1.y-ball0.y;//declares a numeric variable dy, which gets

var jl:number=math.sqrt (Dx*dx+dy*dy)//Declare a numeric variable JL, get the distance of the ball

var qj:number=ball0.width/2+ball1.width/2;//declares a numerical variable to obtain the sum of the sphere radius

if (JL<=QJ) {//If JL is less than or equal to QJ

var angle:number=math.atan2 (DY,DX)//declares a numeric variable angle to obtain BALL1 's angle relative to Ball0

var tx:number=ball0.x+math.cos (angle) *qj*1.01;//declares a numeric variable, TX, to obtain the x-coordinate of the target point

var ty:number=ball0.y+math.sin (angle) *qj*1.01;//declares a numeric variable, ty, to get the y-coordinate of the target point

ball0.vx=-(tx-ball1.x);//ball0 speed in the x direction

ball0.vy=-(ty-ball1.y);//ball0 velocity in the y direction

ball1.vx= (tx-ball1.x);//ball1 speed in the x direction

Ball1.vy= (ty-ball1.y);//ball1 velocity in the y direction

Small series for everyone to edit the FlashCS4 in the production of beautiful bubble animation hope to help!

Related Keywords:

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.