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

Auto Start Flash ActionScript Animation Tutorial

Usually you wish the flash animation starts automatically when the flash movie opens. This flash actionscript animation tutorial shows how to do it.

Please update flash player to view this Flash ActionScript tutorial!

Flash Tutorial Content:

This actionscript tutorial shows how 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 actionscript tutorial. The football will be moved from the left side to the center of the stage of the movie when the Flash Movie starts. An easing (damping) effect is apply to the motion so that the football will be moving slowly and slowly when approaching the destination. You can refresh the browser to reply the animation.

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) {

//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!";



//Start the movement of footaball when the movie start
addEventListener(Event.ENTER_FRAME, moveFootball);

Download Flash Source File:

Flash Source File enter-frame-2.fla


The above flash "animation" will starts automatically when the Flash Movie starts. You can also use button to control when the Flash Movie animation starts. The next Flash ActionScript animation tutorial will show how to use ENTER_FRAME to do that.