Bounce Multiple Objects

Customize with numBalls

Let's finish this project by making it easier to change the number of balls on the stage. Right now, we need to make changes to the condition in two separate for statements:

That's reason enough to pull that number out and turn it into a variable called numBalls. We're going to try something a bit different when we set the data type, though. Instead of using Number (which can be any number, including decimals) we are going to use int (short for integer).

var numBalls:int = 10;

This will free up some computer resources and help avoid errors. Since we can only create "whole" balls, we should restrict the data type to whole numbers.

OK, declare that variable at the very top of the list, then change the condition of those two for statements:

Test... you should now see ten balls bouncing up and down the stage:

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

Get Adobe Flash player