A timer event calls the function of your choice every time the specified amount of time has elapsed.
Download the FLA file
var horizontalSpeed:int = 10;
var verticalSpeed:int = 8;
var ballRadius:Number = ball_mc.width / 2;
var myTimer:Timer = new Timer(20);
myTimer.addEventListener(TimerEvent.TIMER, moveBall);
myTimer.start();
function moveBall(myEvent:Event):void
{
if (ball_mc.x + ballRadius > stage.stageWidth)
{
horizontalSpeed *= -1;
}
else if (ball_mc.x - ballRadius < 0)
{
horizontalSpeed *= -1;
}
if (ball_mc.y + ballRadius > stage.stageHeight)
{
verticalSpeed *= -1;
}
else if (ball_mc.y - ballRadius < 0)
{
verticalSpeed *= -1;
}
ball_mc.x += horizontalSpeed;
ball_mc.y += verticalSpeed;
}