Source: http://blog.csdn.net/m_leonwang/article/details/8811829
Object, array, and dictionary are associative arrays, that is, "keys" to index Storage "value", is the "key-value" pairs of unordered collection.
1.Object
When object is used as an associative array, each property name of the generic object is treated as a key, providing access to the stored value, as shown in the following example:
[Plain]View Plaincopy
- var obj:object = {key1: "value1", Key2: "value2"};
- Trace (obj["Key1"], obj["Key2"]); Output: value1 value2
You can also use the parentheses operator ([]) or the dot operator (.)-that is, dynamic properties to add values to the array:
[Plain]View Plaincopy
- var obj:object = new Object ();
- obj["Key1"] = "value1"; Format error, do not use spaces
- Obj.key2= "value2";
- Trace (obj["Key1"], Obj.key2); Output: value1 value2
But if there is a space in the key, note that the space character can be used with the parentheses operator, but an error is generated when trying to use it with the dot operator, so it is not recommended to use spaces in the key name.
2.Array
Array cannot initialize the array with text, nor can it add elements through attributes, as in the following example:
[Plain]View Plaincopy
- var arr:array = new Array ();
- arr["Key1"] = "value1";
- arr["Key2"] = "value2";
- Trace (arr["Key1"], arr["Key2"]); Output: value1 value2
There is no advantage in creating an associative array using the array constructor, and the key of the array must be a string type, preferably not an array of associative arrays.
3.Dictionary
Dictionary is an associative array with object keys, that is, an associative array that can use objects instead of strings as keys, example code:
[Plain]View Plaincopy
- var groupmap:dictionary = new dictionary ();
- // the object to use as the key
- var spr1:sprite = new sprite ();
- var spr2:sprite = new sprite ();
- var spr3:sprite = new sprite ();
- // the object to use as a value
- var groupa:object = new object ();
- Var groupb:object = new object ();
- // create a new key-value pair in the dictionary.
- groupmap[spr1] = groupa;
- groupmap[spr2] = groupb;
- groupmap[spr3] = groupb;
You can use the for: In loop or for each: In to iterate through the contents of the Dictionary object, the difference is that for: In loops directly accesses the object key of the Dictionary object, and for each: In Access is a value. You can also use the property access operator ([]) to access the value of the Dictionary object:
[Plain]View Plaincopy
- for (var key:object in groupmap)
- {
- trace (Key, groupmap[key]);
- }
- /* output:
- [object sprite] [object object]
- [OBJECT SPRITE] [OBJECT OBJECT]  
- [object sprite] [object object]
- */  
- for each (Var item:object in groupmap)
- {  
- trace (item);
- }
- /* output:
- [OBJECT OBJECT]  
- [ object object]
- [OBJECT OBJECT]  
- */
The way to delete dictionary is:
[Plain]View Plaincopy
- Delete Dic[key];
- If key is an object, remember to release a reference to it
AS3.0 miscellaneous--dictionary, object and array