haXe Forum > How to loop(traverse) Dictionary
-
mac Jul 31 at 05:13
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. -
Scott Campbell Jul 31 at 13:14
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..)
-
Philipp Klose Jul 31 at 14:17
why do you do not use the haXe native Hash-Class. I think it also uses the AVM2 Dictionary.
-
Tony Polinelli Aug 04 at 16:47
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