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 Random Loop Animation Tutorial

For most loop flash animation, the motions are simply repeat again and again as shown in previous tutorial. Therefore this is a bit boring. In this flash actionscript tutorial, we show how to do a random loop animation. In other words, the position of the animation are changing all the time in a random manner.

Please update flash player to view this Flash ActionScript tutorial!

Flash Tutorial Content:

In previous flash actionscript animation tutorial, the football is always enter and leave the stage at the same position. This kind of flash animation is a bit boring because the animation simply repeat again and agin. This would be more wonderful if the ball enter and leave the stage in a random position. In other words, the animation is not just repeat again and again, it is changing all the time. This flash actionscript tutorial will show how to use ENTER_FRAME event to do such random loop animation.

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 Play button to turn on the animation. Click on the Stop button to stop the animation.

Flash ActionScript Codes:

//Function to obtain a random number between two numbers.
function getRandom(minNumber, maxNumber):Number {

var tNumber:Number;
tNumber = Math.round(Math.random()*(maxNumber - minNumber)) + minNumber;
return tNumber;



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
//If location small than the Stage Width, move to right by 1 pixel
//otherwise move back to the left of Stage by 10 pixel
//with random vertical position
if (football_mc.x < 512) {
football_mc.x += 1;} else {football_mc.x = -10;
football_mc.y = getRandom(60, 250);



//Call the moveFootball function when movie starts.
//Therefore the football will start moving when movie starts.

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-6.fla


This Flash ActionScript tutorial showed how to do a random loop animation. Some flash animations like to bounce an object back and forth (like ping pong). The next flash tutorial will show a very basic and simple bouncing animation.