Figure 7-13. Creating a copy of an array
143
ACTIONSCRIPT IN FLEX
In Figure 7-13, we created a copy of our groceries array. Within the copied array, we then changed
the third value, Beef, to Strawberries. When we use trace to look at the values of our arrays, we see
that both the copy and the original array have changed. This is different from the earlier example with
a simpler variable. In that example, myFirstVariable can be changed or even deleted without affecting
mySecondVariable. Why the difference? The answer is that some complex variables in ActionScript
are passed by reference and not by value, thus pointing to the values of the variable rather than creating
a duplicate and independent set of values.
There is now also a more advanced form of arrays: the ArrayCollection. Collections, which are
ActionScript 3.0 classes, are unique to Flex. In simple terms, this is a class that envelops the Array
class, adding a number of convenient ways to interact with the values of the array. Explaining arrays
and collections in detail is beyond the scope of this chapter, but it is important to at least know they
exist. The ArrayCollection class exists for convenience. Array has a number of basic methods to
manipulate data, but when doing complex operations, ArrayCollection offers methods that could
take several operations to accomplish using a normal array.
Accessing external data
There are a few ways to access or load external data and assets in Flex. Bringing content dynamically
into our applications is essential in order to create content that intelligently loads assets on demand,
to adapt to the audience by displaying localized interfaces, or simply to better organize large applications
into more manageable pieces.
Pages:
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115