Chapter 5: Arrays: Match Em up and Sliders


In this chapter, we'll first be looking at the concept of arrays. After we break down this fundamental programming principal, we'll see several examples of how arrays are used in ActionScript. From there, we'll look at two new games that use the concept of arrays heavily in their implementation.

After completing this chapter, your ability to implement complex games will grow dramatically. Arrays allow you to organize data so that it can be accessed easily, and that will help you by removing your need to know the name of every variable in advance. If you have a number of things in a game but you don't know how many there will be, you can use an array to contain them and then forget about their names .

What Is an Array?

An array is simply a block of variables. None of the variables in an array has a name; instead, variables are accessed using the name of the array with an index that represents which of the variables in the block you are referring to. Figure 5.1 shows an array.


Figure 5.1: An array is a block of variables.
Note  

The use of arrays in ActionScript is optional; there is nothing you can do with an array that you can't do in some other fashion. But arrays do make your life easier. For that reason, we'll be using them in nearly every game in this book in some way or another.




Macromedia Flash MX 2004 Game Programming
Macromedia Flash MX 2004 Game Programming (Premier Press Game Development)
ISBN: 1592000363
EAN: 2147483647
Year: 2004
Pages: 161

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net