Hi Michael,
That's how the for-in loop works, no idea why.
If you want to count forwards, you need to use:
for (var i:Number = 0; i<myArray.length, i++) {
trace(myArray[i]);
}
There's a pretty good reason, in fact (or at least, this is why it's done in
Director, can't speak for Flash). The reason is that if you delete an
element from an array while looping through it, you don't want to lose
count. I often count down through arrays for this reason.
Silly example (obviously, pop() would be a better command here)
var tArray:Array = new Array(1, 2, 3, 4, 5, 6);
for (var i = 0; i<tArray.length; i++) {
tArray.splice(i, 1);
}
trace(tArray);
// 2,4,6
tArray = new Array(1, 2, 3, 4, 5, 6);
for (i=tArray.length-1; i>=0; i--) {
tArray.splice(i, 1);
}
trace(tArray);
//
Danny
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com