Prev | Current Page 102 | Next

LordAlex Leon, Greg Goralski

"Foundation Flex for Designers"

Let??™s have a closer look at arrays.
Arrays are a special type of container that can generally hold multiple values ordered by an index. In
real life you have used arrays without knowing it. When you write a grocery list, for example, your list
contains a number of items; you can think of groceries as the name of the array that holds the items
you need to purchase.
It would look something like this:
groceries:
Milk Chicken
Eggs Carrots
Beef
142
CHAPTER 7
We use arrays in programming for the same reason you??™d create a grocery list: it??™s convenient. You create
your grocery list so you can easily iterate all the items and mark them off as you find them in the
supermarket.
Figure 7-9 shows how our list would look in ActionScript.
Figure 7-9. The array groceries
To access the first element in the groceries array, use the name of the array as an index (Figure 7-10).
Notice that arrays in ActionScript are zero based, which means [0] and not [1] is the first element of
the array.
Figure 7-10. Tracing the array groceries
To change a value on this list, we also use the array index (Figure 7-11).
Figure 7-11. Changing the array groceries
Another advantage of using arrays is the methods we can use to work with the data they hold. One
such method is Array.length, which returns the number of values contained in the array. Figure 7-12
shows an example.
Figure 7-12. Getting the length of an array
You can also pass an array value to another array, but the results are a bit different (Figure 7-13).


Pages:
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
mapa muzykowo filmy w sieci Losza Vera M-People Magic Affair