- Home
- Tutorials
- Flash
- Intermediate
- Balls chain with constraints, colision, mouse follow and the math needed

Attaching Balls in the scene
We are going to attach each ball from the library.
Since we created a new Math class, we are going to import it before we can do anything with that file, so in the first frame in the root, put this line of code:
import Math2;
Now, is time to add the balls. We are going to use a function for that, and it will be called "init". The code:
function init() { balls = 20; reductionMultiplier = 1; for (i=1; i<=balls; i++) { this.attachMovie("circle","mc"+i,_root.getNextHighestDepth(),{_x:30*i, _y:200}); } } init();
"balls" is the number that we are going to attach, you can use whatever you want if the performance is good for you. "reductionMultiplier" is just a multiplier to define how fast each movie will follow the other one. So, if you use a number higher than 1, it will become slowly and elastic.
After the variables, we have a simple loop for balls creation (attachMovie). Initial position is up to you.
Finally, we call the function by using the "init()" line.

