actionscript 3 - Accessing Array Length comes back as Zero -
i have array in actionscript 3 formatted follows:
var _arraylist = new array; _arraylist["item1"] = true; _arraylist["item2"] = 56; _arraylist["item3"] = "john doe"; _arraylist["item4"] = -56.8;
and i'm attempting pull "_arraylist.length" comes 0... why?
because way makes array "associative". in action script, every class basic object, dynamic properties. , array both - containing indexed elements, , having dynamic properties.
here's illustration of regular array:
var array:array = new array(); array.push(value); // equal array[0] = value; array.push(56); // equal array[1] = value; array[20] = 'test'; // set 20th element 'test'
if utilize approach, length
of array not 0
. , can utilize for
loop:
var total:uint = array.length; (var i:uint = 0; < total; i++) { trace (array[i]); }
but when keys not numeric, setting "properties" array , length 0
. again, can loop through them, for-in
:
for (var key:string in array) { trace (array[key]); }
here keys won't 0, 1, 2, 3
, on, instead item1, item2, item3
. (keep in mind order not preserved!)
so basic conclusion if utilize non-numeric keys, utilize object instead. array numeric indexed collections.
arrays actionscript-3
No comments:
Post a Comment