Hi, guys!
I’m a level 0 student of AS3.
How does one multiply the bouncing balls in the following code which I saw in one of the threads in the forum? Let’s just say I want to see 10 bouncing balls. How should I go about it?
CODE:
var ball:Sprite = new Sprite ;
addChild(ball);
ball.graphics.beginFill(Math.random()*0xff0000);
ball.graphics.drawCircle(0,0,10);
ball.graphics.endFill();
ball.x = stage.stageWidth / 2;
ball.y = stage.stageHeight - ball.height;
var speedX = +10;
var speedY = -10;
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
function enterFrameHandler(event:Event):void
{
ball.x += speedX;
ball.y += speedY;
var bounds:Rectangle = ball.getBounds(stage);
if (bounds.left < 0 || bounds.right > stage.stageWidth)
{
speedX *= -1;
}
if (bounds.top < 0 || bounds.bottom > stage.stageHeight)
{
speedY *= -1;
}
}