I haven't touched flash for a long time. Today I have reviewed as3.0 and made a rebound effect.
I was thinking about how to define different colors of bubbles so that we can make more beautiful effects, or make more progress 1. The bubbles and bubbles will rebound directly. If I haven't figured it out for a long time, let's do it first, updating when there are better solutions
Slice
As code
Package
{
Import flash. display. Sprite;
Import flash. Events. event;
Import flash. display. stagealign;
Import flash. display. stagescalemode;
Public class bubble extends Sprite
{
Public var count: Int = 6;
Public var bballs: array;
Public Function bubble ()
{
Init ();
}
Private function Init (): void
{
Stage. align = stagealign. Left;
Stage. scalemode = stagescalemode. no_scale;
Bols = new array;
For (VAR I = 0; I <= count; I ++ ){
VaR ball = new ball ();
// Ball. Alpha = math. Random ();
Ball. x = math. Random () * stage. stagewidth;
Ball. Y = math. Random () * stage. stageheight;
Ball. VX = math. Random () * 3-3;
Ball. Vy = math. Random () * 3-3;
Addchild (ball );
Bils. Push (ball );
}
Addeventlistener (event. enter_frame, onenterframe );
}
Private function onenterframe (Event: Event): void
{
VaR left = 0;
VaR Top = 0;
VaR Bottom = stage. stageheight;
VaR right = stage. stagewidth;
For (var I: Number = bils. Length-1; I> = 0; I --){
VaR ball = bils [I];
VaR radius: Number = ball. width/2;
Ball. x + = ball. VX;
Ball. Y + = ball. Vy;
If (ball. x> right-radius ){
Ball. x = right-radius;
Ball. VX * =-1;
}
If (ball. x <radius ){
Ball. x = radius;
Ball. VX * =-1;
}
If (ball. Y> bottom-radius ){
Ball. Y = bottom-radius;
Ball. Vy * =-1;
}
If (ball. Y <radius ){
Ball. Y = radius;
Ball. Vy * =-1;
}
}
}
}
}
File Download
Flash bounce .rar