Working with Arrays

If Statement

Let's start by opening the ball_for.fla we've been working on. We may want to go back in case we ruin it, so click File > Save As and name our new file: ball_array

When we left off, we were able to control that single copy of ball after the for loop. But that was it! Start by getting rid of the last line of code setting myBall.y = 50:

We'll now create a new type of Object: an Array

Programmers use arrays to store (and access) individual values for a group of identical variables. In our case, we are going to store the individual "names" for our group of identical balls.

In fact, balls is a good name for our array. Create it like this:

Our Array is created, but is essentially "empty" right now.

We want to populate our array with a new reference every time we add a copy of ball to the stage. The push function adds an entry to our array: