How to find the length of an associative array in ActionScript 3.0

actionscript-3apache-flexarrays

Is there a simple way to retrieve the length of an associative array (implemented as an Object) in ActionScript 3.0?

I understand that there are two primary ways of creating associative arrays in AS3:

  1. Use a Dictionary object; especially handy when the key does not need to be a string
  2. Use an Object, and simply create properties for each desired element. The property name is the key, and the value is, well, the value.

My application uses approach #2 (using the Object class to represent associative arrays).

I am hoping there is something more native than my for loop, which manually counts up all the elements.

Best Answer

You have to count them in a for loop as you do. Of course, you could make a class and stick the for loop in that class.

For some great implmentations of Collections in AS3, check these guys.

Edit 2013 Not surprisingly, links do break after time. Try this new one: http://www.grindheadgames.com/get-the-length-of-an-object.