Actionscript: Associative vs List-like Array

May 1, 2008 § Leave a comment

Constructing Arrays

In Actionscript, Associative array is not defined using Array type. To construct associative array, one must use Object type.

e.g. var assocArray:Object = new Object();

Array type is strictly behaving like an ordered, numerically indexed, list.

e.g. var regArray:Array = [‘a’, ‘b’, ‘c’];

Arrays Length

Array type has length property. This length property can be used in for loop.

e.g. for(var i:int = 0; i < array.length; i++) { … }

On the other hand, Object does not have length property. In order to loop through every property in an Object, one can use a different syntax of for loop.

e.g. for(var i:String in assocArray) { trace(assocArray[i]); }

References

Flex 3 Langref – Object

Flex 3 Langref – Array

Advertisements

Tagged: , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

What’s this?

You are currently reading Actionscript: Associative vs List-like Array at RAPD.

meta

%d bloggers like this: