# Multiplying instances?

**URL:** <https://forum.kirupa.com/t/multiplying-instances/324133>\
**Category:** flash\
**Created:** [August 4, 2011, 12:01am UTC](https://forum.kirupa.com/t/multiplying-instances/324133 "2011-08-04T00:01:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![randa2723](https://avatars.discourse-cdn.com/v4/letter/r/9fc348/32.png) [@randa2723](https://forum.kirupa.com/u/randa2723)\
**Post date:** [August 4, 2011, 12:01am UTC](https://forum.kirupa.com/t/multiplying-instances/324133/1 "2011-08-04T00:01:41Z")

</div>

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 &lt; 0 || bounds.right &gt; stage.stageWidth)
{
    speedX *= -1;
}

```

if (bounds.top \< 0 || bounds.bottom \> stage.stageHeight)  
{  
speedY \*= -1;  
}

}
