Bouncing Ball (Ball Dribble) Animation Using Flash And Action Script
This Flash script will result in animation of a ball that will be bounced when it hit a floor (ball dribbling). You can even move the ball. Click on it and hold to stop the bouncing and then release the mouse to continue bouncing. What we need to produce the animation is just a movie clip an a simple script.
Preview
Source Code
[as3]//By : Isusx’s Programming Corner
//URL : http://isusx.com/
//Variable declarations and initialization
_animate = true;
_bounce = 35;
_velocity = 12;
_elasticity = 0.8;
_floorY = Stage.height/2;
_reflex = 5;
//Animate process
this.onEnterFrame = function(){
if (_animate){
mc_ball._y += _bounce;
_bounce += _velocity;
if (mc_ball._y > _floorY){
mc_ball._y = _floorY;
_bounce = -(_bounce * _elasticity) + _reflex;
if (Math.abs(_bounce) <= _reflex)
_bounce = 0;
}
}
}
//On press event, the ball will stop bouncing and drag mode is on
mc_ball.onPress = function(){
_animate = false;
_bounce = false;
mc_ball.startDrag(true);
}
//On release event, the ball will start bouncing and drag mode is off
mc_ball.onRelease = function(){
_animate = true;
mc_ball.stopDrag();
}
[/as3]
Download
Click here to download the source code
Copyright Note
This script is free to use and can be modified as you wish.
Related Links
Flash Documentation, Guide and Complete Reference




