18Jul

Associative Arrays with the Object Class

No comments

To create an associative in Actionscript 3 you will need to use the object class because of the named elements (vs. the numbered elements).

var assocArr:Object = {fName:"Morgan", lName:"Newcomb"};
trace(assocArr.fName);     // Output: Morgan
trace(assocArr["lName"]);  // Output: Newcomb

To add an element, you can add this to your code

assocArr.mi = "A";
trace(assocArr.mi);   // Output: A

Share/Save/Bookmark

Categories: Actionscript 3, Arrays

Friday, July 18th, 2008 at 9:54 am and is filed under Actionscript 3, Arrays. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a reply