Prev | Current Page 105 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


Arrays
Arrays are the primary type for storing lists of values and provide the easiest methods for adding and
extracting the values contained in the Array. Much of the syntax for haXe Arrays are similar to that of
Java and ActionScript, so developers with knowledge of these languages should be able to scan this
section for the minor changes.
Before using an Array in haXe, it must be instantiated, unless you initialize the Array with a literal list.
This is discussed in more detail in Chapter 5 , ??? Delving Into Object - Oriented Programming. ??? However,
for the purposes of this chapter, you simply pass new Array(); to the Array variable before working
with it:
var myArray : Array < Int > = new Array();
You do not need to re - specify the contained data type in the instantiation, and indeed, any type identifier
added to the second Array keyword is discarded.
You can empty an Array of all data by re - instantiating it. However, in order to change the data type
associated with an Array, a new Array object will need to be declared and instantiated.


Pages:
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117