How can i add multiple balls?
var ballSpeedX:int = -9;
var ballSpeedY:int = -12;
init();
function init():void
{
stage.addEventListener(Event.ENTER_FRAME, loop);
}
function loop(e:Event):void
{
ball.x += ballSpeedX;
ball.y += ballSpeedY;
if(ball.x <= ball.width/2){
ball.x = ball.width/2;
ballSpeedX *= -1;
} else if(ball.x >= stage.stageWidth-ball.width/2){
ball.x = stage.stageWidth-ball.width/2;
ballSpeedX *= -1;
}
if(ball.y <= ball.height/2){
ball.y = ball.height/2;
ballSpeedY *= -1;
} else if(ball.y >= stage.stageHeight-ball.height/2){
ball.y = stage.stageHeight-ball.height/2;
ballSpeedY *= -1;
}
if(ball.hitTestObject(wall.wallu) || ball.hitTestObject(wall.walld))
{
ballSpeedY *= -1;
}
if(ball.hitTestObject(wall.walll) || ball.hitTestObject(wall.wallr))
{
ballSpeedX *= -1;
}
}
