Creating a Loop

new ball review

Let's start by opening ball_addChild.fla

We may want to go back, so click File > Save As and name our new file: ball_for

Right now, our script adds a single child of the ball class, names it ball1, and positions at (100,150). What if we want to add a second child? Why not try it, with name ball2 and position (150,100):

var ball1:ball = new ball();
ball1.x=100;
ball1.y=150;
addChild(ball1);
var ball2:ball = new ball();
ball2.x=150;
ball2.y=100;
addChild(ball2);

That works:

Content on this page requires a newer version of Adobe Flash Player.

Get Adobe Flash player

... but it's going to get old real quick if we want to add even more balls to the stage. Imagine doing that twenty or thirty (or a hundred) times! Imagine changing your mind.... you'd lose your mind! There must be a better way.