While working on a project that dealt with some heavy array manipulations, I have started using more and more of Flash’s utilities for quick array modifications. A couple of useful commands are the following:

// sorting movieclips in an array by x position
myArrayofMCs.sortOn("x", Array.NUMERIC);
// Fast 'for each' method for array item operations
// This is generally faster than the common for(var i:int=0, i < arrayLength; i++) {}
for each ( var mc:MovieClip in myArrayofMCs ) mc.buttonMode = true;
// Finding the index position of an item that is in an array that was clicked on
function onClick(e:MouseEvent):void {
 var itemIndex:int = myArrayofMCs.indexOf(e.currentTarget);
}

Author: Jonathan Dunlap
Jonathan is a veteran software architect, author of IsoHill, humanitarian, and has worked with Bigpoint Inc, CrowdStar, ePrize, and Microsoft.

Tags: