haXe Forum > How to loop(traverse) Dictionary

  • In AS3 i can loop(traverse) Dictionary by this way:
    ''for (var i:* in dict){
    trace(i);
    }''

    But in haxe,when i do it in the same way, it will alert "Dictionary has no field iterator".
    How can i solve this problem and traverse the haxe Dictionary .Thanks.

  • I'm guessing, because haXe is looking for a data structure that has the iterable interface , and the native flash class does not have the iterator() function.

    You can extend the class, and add the function.

    or you could manually loop though it..
    <code haxe>
    for(var i:int = 0; i > dict.length;i++){
    trace(dict[i]);
    }
    <code/>
    or something like that.

    Or you could try use one of the haXe data structures instead?

    (I may have a few details wrong, I'm pretty new to the haXe scene..)

  • why do you do not use the haXe native Hash-Class. I think it also uses the AVM2 Dictionary.

  • You should have a look at the TypedDictionary class as it wraps dictionary to provide the iterator, aswell as methods for getting and setting values
    http://haxe.org/api/flash9/utils/typeddictionary

< Prev | Page 1 / 1 | Next >