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

Start Flash ActionScript Animation with Button

This Flash ActionScript shows that the flash animation will be started when users click on a button.

Please update flash player to view this Flash ActionScript tutorial!

Flash Tutorial Content:

This flash animation tutorial shows how to use a button to move the football smoothly from one location to another with ENTER_FRAME event.

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. The football will be moved from the left side to the center of the stage of the movie when you click on the play button. An easing (damping) effect is also apply to the motion so that the football will be moving slowly and slowly when approaching the destination.

Flash ActionScript Codes:

//Set a damping factor of the movement of football (easing factor)
var easing:Number = .2;

//Location (destinationX) the football will be move to
//The football will be moved to the center of stage
//stage.stageWidth = 512
//center of stage = 256
var destinationX:Number = stage.stageWidth / 2

//Indicate the moving Start Point and End Point of football
output_txt.text = "Start point of footabll is: " + football_mc.x;
output_txt.text = output_txt.text + "\n" + "End point of football is: " + destinationX;


function moveFootball(evt:Event) {

//Identify the moveFootball function as our event handler
addEventListener(Event.ENTER_FRAME, moveFootball);
//Approach the destination with easing
//For example:
//at beginning, football will move (256 - 70) * .2 = 37.20
//when close to destination, football wil move (256 - 200) * .2 = 11.20
//Therefore football will be moved fast at begiining and
//slower and slower when close to destination
football_mc.x += (destinationX - football_mc.x) * easing;

//Need to stop the easing otherwise it will execute continously
//It seems that football_mc.x can never equal to destinationX
//Therefore it is better to use the difference
if ((destinationX - football_mc.x) < 0.5) {
//Remove the Listener otherwise
//it will keep on working and consume computer resources
removeEventListener(Event.ENTER_FRAME, moveFootball);
//Let the user know that the football reach the destination
output_txt.text = output_txt.text + "\n" + "Reach the destination!";



//The footabll move when the Play button click
play_btn.addEventListener(MouseEvent.CLICK, moveFootball);

Download Flash Source File:

Flash Source File enter-frame-3.fla


You should see flash animation on the Internet that an object will move to the mouse pointer when user click the mouse on any location on the screen. The next Flash ActionScript tutorial will show how to use ENTER_FRAME to do that.