Alex Rivera | Logout

For-Each Loop AS3: Is the direction guaranteed?

Asked 2009-03-06T14:07:57.687
13

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 iteration order of these loop type combinations?

For example I presume that using a for-each on an Array type always move from the first element to the last. For-each cannot be used on a Dictionary so how is the order determined using a for-in loop?

Edit
Report

1 Answer

8

As stated in Essential Actionscript 3.0 by Colin Moock, the order of a for each in loop is not guaranteed unless enumerating an XML or XMLList object;

Click here for Colin Moock's words from his book.

There are workarounds as discussed here, but honestly if you need to guarantee the order then just use a regular old for loop and have it iterate (length, numChildren, etc.) number of times.

answered 2009-03-07T00:34:17.090

Your Answer