Prev | Current Page 112 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


insert accepts two parameters: the location to add the value and the value you want inserted. Once
you have inserted the value, all items that exist after the specified location are moved up by one position:
myArray.insert(4, someValue);
Copying and Concatenating Arrays
Arrays are objects and not of the haXe base types list. Because of this, passing an Array from one variable
to another will not create a duplicate of the Array, but will merely create two variables that point to the
same information in memory. This means that modifying one Array will automatically modify the other
Array. You do not want to get into this too deeply for now, as this is the subject of a whole other chapter,
but needless to say, if you want to duplicate the structure of an Array into a new Array, you will need
some help. Thankfully, haXe provides you with some tools to do just that, in the guise of slice and copy .
Slice()
The slice method takes two parameters and returns a chunk of the Array, which just happens to look
and work very similarly to the splice method.


Pages:
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124