import flash.events.Event; //create a var named tempBubble, define it as Object type var tempBubble:Object; stage.addEventListener(Event.ENTER_FRAME, moveBubbles); function moveBubbles(evt:Event) { for(var m = 0; m <= bubbleContainer.numChildren - 1; m++) { tempBubble = bubbleContainer.getChildAt(m); tempBubble.x += tempBubble.xmov; tempBubble.y += tempBubble.ymov; //using the hitTestObject method look for a collision between the tempBubble and the leftWall or //the tempBubble and the rightWall if(tempBubble.hitTestObject(leftWall) || tempBubble.hitTestObject(rightWall)) { //reverse the direction by changing the xmov property of the tempBubble tempBubble.xmov *= -1; } //using the hitTestObject method look for a collision between the tempBubble and the topWall or //the tempBubble and the bottomWall if(tempBubble.hitTestObject(topWall) || tempBubble.hitTestObject(bottomWall)) { //reverse the direction by changing the ymov property of the tempBubble tempBubble.ymov *= -1; } } } function createBubbles(bubbleCount) { for(var b = 1; b <= bubbleCount; b++) { var newBubble:bubble = new bubble(); newBubble.x = stage.stageWidth / 2; newBubble.y = stage.stageHeight / 2; newBubble.xmov = (Math.random() * 6) + 1; newBubble.ymov = (Math.random() * 6) + 1; bubbleContainer.addChild(newBubble); } } //add a numerical value 1 to 100 to the createBubbles function call below, you can play with the values to see what happens createBubbles(Math.random()*100);