You can use the for .. in loop or for each .. in loop to cyclically access the contents of a dictionary object. For .. in loops are used to perform circular access based on keys, while for each .. in loops are used to perform circular access based on the values associated with each key.
You can use the for .. in loop to directly access the object key of the dictionary object. You can also use the attribute access operator ([]).
Value of the dictionary object. The following code uses the previous groupmap dictionary example to illustrate how to use the for... in loop for loop access
Dictionary object: For (var key: object in groupmap)
{
Trace (Key, groupmap [Key]);
}
You can use the for each .. in loop to directly access the value of the dictionary object. The following code uses the groupmap dictionary to demonstrate how to use the for each .. in loop to cyclically access a dictionary object: For each (VAR item: object in groupmap ){
Trace (item );
}
Delete the myobject key from mymap:
Delete mymap [myobject];
__________________________________________________________________
About flex objects and Dictionary
RecommendedDictionary,
It is best to replace the object (the object will not be detected by the editor ),
The following is the online dictionary
The dictionary class (flash. utils. dictionary) in as3 is a new as class. The only difference between a dictionary class and an object is that a dictionary object can use a non-string as the key of a key-value pair. For example:
VaR OBJ: Object = new object ();
OBJ ["name"] = 1; // The key is the string "name"
OBJ [1] = 2; // The Key is 1 (converted to a string "1 ")
OBJ [new object ()] = 3; // The Key is new object (), which is converted to a string "[object]"
For (VAR prop: String in OBJ ){
Trace (PROP); // output: [object], 1, name
Trace (OBJ [prop]); // output: 3, 2, 1
}
That is to say, no matter what type of variable is used as the key, it will be converted into a string. At the same time, if you use different objects as keys, they will be converted to the string "[object]" as keys, and therefore point to the same data. For example:
ActionScript code:
VaR A: object = new object ();
VaR B: Object = new object ();
VaR OBJ: Object = new object ();
OBJ [a] = 1; // OBJ ["[object]"] = 1;
OBJ [B] = 2; // OBJ ["[object]"] = 2;
For (VAR prop: String in OBJ ){
Trace (PROP); // traces: [object]
Trace (OBJ [prop]); // traces: 2
}
The dictionary class does not have this restriction. You can set the key to any data type. For example:
Import flash. utils. dictionary;
VaR A: object = new object ();
VaR B: Object = new object ();
VaR dict: dictionary = New Dictionary ();
Dict [a] = 1; // dict [a] = 1;
Dict [B] = 2; // dict [B] = 2;
For (VAR prop: * In dict ){
Trace (PROP); // traces: [object], [object]
Trace (dict [prop]); // traces: 1, 2
}
Although [object] is output during trace, this result is the tostring result of the object. In a dictionary object, different object references are represented.
Input true in the direary ary class Constructor
VaR dict: dictionary = New Dictionary (true); // use weak references as keys
VaR OBJ: Object = new object ();
Dict [OBJ] = true;
Delete OBJ;
Although dict references OBJ, it is not a valid reference, so OBJ will still be recycled