My friend Iacob showed me an interesting livedocs comment on the Performing Object Introspection page. It seems that if you try to change values while you are in a for loop, everything kind of gets messed up.

For example take the following code :

For instance:

1. var obj : Object = {};
2. obj.a = "x";
3. obj.b = "y";
4. obj.c = "z";
5. for(var key:String in obj){
6. obj[key] = obj[key]+"x";
7. trace(key+"="+obj[key]);
8. }
Generated by FlexWebFormater


The most interesting thing I found is that you can use the new Object() instead of {} and it works fine.

If you do another for right after that and just trace the output you see that properties a and c were affected (and show once) while property b was not affected by the previous for (not changed).

Weird, but as I said, you can use new Object() instead of the curly brackets {} to get rid of this problem.