在 AS3 编程中,免不了要使用Object 和 Dictionary , 实际上 本人 很多时候 是使用 Vector 或者 Dictionary 的 . 因为 , Vector 的 效率 是 最高的 , 而 Object 和 Dictionary 次之 , 这里 我只讲 Object 和 Dictionary 的 遍历.

   以 Key 进行的遍历:

   Object ->

for(var $key : * in Obj ){
    trace("Key -> "+ $key);
    trace("Obj 元素 ->" + Obj[$key]);
    //当然 可以 保存 $key  若 Obj 当中的Key 为 Uint 则:
    var myKey : uint = $key as uint;
}

   Dictionary ->

for(var $key : String in Dic){
    trace("Key-> "+ $key);
    trace("Dic 元素 -> "+Dic[$key]);
    var myKey : String = $key;
}
 

       这里假设 Dic 中的Key 为String

   以Item 进行遍历

   Object ->

for each(var $item : * in Obj){
    trace("Obj 元素 -> " + $item);
}

   Dictionary ->

for each(var $item : Model in Dic){
    trace("Dic 元素 -> "+$item);
}