# Attach multiple moving balls

**URL:** <https://forum.kirupa.com/t/attach-multiple-moving-balls/212974>\
**Category:** Uncategorized\
**Created:** [January 16, 2007, 1:48am UTC](https://forum.kirupa.com/t/attach-multiple-moving-balls/212974 "2007-01-16T01:48:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![chaoti](https://avatars.discourse-cdn.com/v4/letter/c/e47c2d/32.png) [@chaoti](https://forum.kirupa.com/u/chaoti)\
**Post date:** [January 16, 2007, 1:48am UTC](https://forum.kirupa.com/t/attach-multiple-moving-balls/212974/1 "2007-01-16T01:48:38Z")

</div>

The code below is supposed to create a seperate ball every second that is affected by wind and gravity, but it attaches and nothing happens. Any suggestions?

* * *

counter = 0;  
setInterval(plusball, 1000);  
function plusball() {  
for (var i = 0; i\<2; i++) {  
\_root.attachMovie(“ball”, “bal;”+counter, i);  
counter++;  
bl = \_root[“ball”+counter];  
bl.\_x = bl.dx;  
bl.\_y = bl.dy;  
bl.onEnterFrame = function() {  
this.\_x += this.dx;  
this.\_y += this.dy;  
if (this.\_x+this.\_width/2\>400) {  
this.\_x = 400-this.\_width/2;  
this.dx \*= -bounce;  
}  
if (this.\_x-this.\_width/2\<0) {  
this.\_x = 0+this.\_width/2;  
this.dx \*= -bounce;  
}  
if (this.\_y+this.\_height/2\>400) {  
this.\_y = 400-this.\_height/2;  
this.dy \*= -bounce;  
}  
if (this.\_y-this.\_height/2\<0) {  
this.\_y = 0+this.\_height/2;  
this.dy \*= -bounce;  
}  
[//this.dy](https://this.dy) += .4;  
bounce = 1;  
float = 1;  
tx = 2;  
var windDX = Math.cos(windAngle)\*windSpeed;  
var windDY = Math.sin(windAngle)\*windSpeed;  
this.dx += windDX;  
this.dy += windDY;  
windAngle += 0.03;  
};  
}  
}  
windAngle = -10;  
windSpeed = .4;
