Try to compile:
var object:Object = {};
object.one = "foo";
object.two = "foo";
object.three = "foo";
object.four = "foo";
for(var key:String in object)
{
trace(key);
}
... you will get:
one
four
two
three
Why the messed up order?
Try to compile:
var object:Object = {};
object.one = "foo";
object.two = "foo";
object.three = "foo";
object.four = "foo";
for(var key:String in object)
{
trace(key);
}
... you will get:
one
four
two
three
Why the messed up order?
The keys of an object are not ordered. If you need to preserve order and have a lookup, then you need to create a custom collection that provides that functionality.
What "messed up" order?
There is no order to properties on an object. for...in
can iterate over them in whatever order it likes.
Object in AS3 can be seen as a hashtable where the field name is the key. So you cant rely on the creation order to get the same order when loop throught the field, the order will depend on the algorithm used for hashing the field name.