Flash as 3.0 Example Tutorial: Main class to create divergent effects

Source: Internet
Author: User

1, new Flash document, 550*400, other default.

2, create a movie clip, select the Ellipse tool, no strokes, fill color radiation gradient, draw an ellipse (shape custom, I phase you will be better than I do), the right key library to set the link, class name ball.

3, return to Scene 1, the first layer of background (random), new as layer, in the as layer of the first frame input code:

The initial position of the ball
[Initial position of code]//ball
var ballx:number = 275;
var bally:number = 400;
Speed of small ball movement
var speed:number = 5;
Stage.addeventlistener (Mouseevent.click,shoot);
function Shoot (e:mouseevent): void
{
for (var i:int = 1;i<9;i++)
{
Create a ball from the library
var ball:ball = new ball ();
Initialize the ball position
ball.x = BALLX;
BALL.Y = Bally;
Calculate the velocity of a ball according to trigonometric functions
BALL.SPDX = Cosd (i*-20) *speed;
Ball.spdy = SinD (i*-20) *speed;
Registering Enterframe Events
Ball.addeventlistener (Event.enter_frame,ballmove);
E.target.addchild (ball);
}
}
function Ballmove (e:event): void
{
Get a reference to the ball
var obj:movieclip = E.target;
Set the coordinates of the ball to achieve motion
obj.x + + OBJ.SPDX
OBJ.Y + + Obj.spdy
if (obj.y<0| | obj.x<0| | obj.x>550| | obj.y>400)
{
Remove Enterframe Event
Obj.removeeventlistener (Event.enter_frame,ballmove)
Remove from Display list
Stage.removechild (obj)
}
}
Angle conversion to radians
function Angletoradian (angle:number): number
{
Return angle* (math.pi/180);
}

function SinD (angle:number): number
{
Return Math.sin (Angletoradian (angle));
}
function Cosd (angle:number): number
{
Return Math.Cos (Angletoradian (angle));
}

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.