Flash AS3 Tutorials Center | Interesting Flash Animation Tutorials | Valuing Flash Animation Tutorials | Flash ActionScript and Animation Home

AS3 Beginner Tutorials | AS3 Basic Lessons | AS3 Valuing Courses | AS3 Components Tutorials | AS3 and PHP Interaction Tutorials
AS3 Practical Tutorials | AS3 Animation Techniques | AS3 Transition Effects Tutorials | AS3 Download Upload Files | AS3 Particle Systems
Communication Between Flash Movies with AS3 | AS3 and JavaScript interaction | AS3 Matrix Transformation | AS3 Physics Simulation Tutorials

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.

Please update flash player to view this Flash ActionScript tutorial!

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 {

//Use ENTER_FRAME event to fire action for every frame.
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 < 480) {football_mc.x += 1;

if (football_mc.x == 479) {
moveRight = false;}}
} else {football_mc.x -= 1;

if (football_mc.x == 30) {
moveRight = true;}}

}

 

//Call the moveBall function when movie starts.
//Therefore the football will start moving when movie starts.
moveFootball(null);


function stopFootball(eve:Event):void {

stage.removeEventListener(Event.ENTER_FRAME, moveFootball);

}

 

//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:

Flash Source File enter-frame-7.fla

Remarks:

This Flash ActionScript tutorial showed how to do a bounce or bouncing animation.