Flash ActionScript Bouncing Animation Tutorial
In this flash actionscript tutorial, we will do a bounce animation, i.e. the object is bouncing around on the stage.
Flash Tutorial Content:
In previous flash actionscript animation tutorials the football is always leave the stage on the left and enter the stage again from the right side. In this flash tutorial we do a very simple and basic bouncing animation of the football, i.e. the football is bouncing between the left side and right side.
The complete Flash Movie is shown as above, you may try how it works before you start this tutorial. Click on the above flash movie to select it to start. Click on the Stop button to stop the animation. Click on the Play button to turn on the animation.
Flash ActionScript Codes:
//Keep track with the football moving direction
var moveRight:Boolean = true;
function moveFootball(evt:Event):void {
stage.addEventListener(Event.ENTER_FRAME, moveFootball);
//Set the frame rate
stage.frameRate = 15;
//Display location of the Footabll in the Message TextField.
output_txt.text = "Location of ball: " + football_mc.x + "," + football_mc.y;
/*
Keep track the location of the ball:
Case 1: Ball moving to the right
- If location less than 480, move to right by 1 pixel
- Change the move direction to left (moveRight = false)
Case 2: Ball moving to the left
- Keep moving to the left by 1 pixel until location is 30
- Change the move direction to right when location is 30
*/
if (moveRight == true) {
if (football_mc.x == 479) {
if (football_mc.x == 30) {
}
//Call the moveBall function when movie starts.
//Therefore the football will start moving when movie starts.
moveFootball(null);
function stopFootball(eve:Event):void {
}
//Button to stop the football
stop_btn.addEventListener(MouseEvent.CLICK, stopFootball);
//Button to move the football
play_btn.addEventListener(MouseEvent.CLICK, moveFootball);
Download Flash Source File:
Remarks:
This Flash ActionScript tutorial showed how to do a bounce or bouncing animation.