For-Each Loop AS3: Is the direction guaranteed?

前端 未结 3 657
暗喜
暗喜 2020-12-11 15:33

I would like to know the iteration order for the Array, Dictionary and Object types in AS3, for both the for-each and the for-in loops. Also what factors can change the iter

3条回答
  •  借酒劲吻你
    2020-12-11 16:00

    The order of evaluation changed in AS3.0 Earlier, in AS 1.0 and 2.0, the order of evaluation was based on the order in which the objects were added. Now, in 3.0, all looping maintains array order. Try the snippet:

    var a:Array = new Array();
    a[ 1 ] = 'first';
    a[ 0 ] = 'second';
    
    for (var key:String in a) 
        trace( key + ': ' + a[ key ] );
    

    Try the above with AS3.0 and AS1.0/2.0

提交回复
热议问题