myData.length // Check firstIndex is within valid bounds
|| secondIndex < 0 || secondIndex > myData.length // Check secondIndex is within valid bounds
|| firstIndex == secondIndex) // No need to swap if firstIndex equals secondIndex
return false;
var temp:Object = myData.getItemAt(firstIndex); // Store the item at firstIndex in a temporary object
myData.setItemAt(myData.getItemAt(secondIndex), firstIndex); // Update the item at firstIndex
myData.setItemAt(temp, secondIndex); // Update the item at secondIndex
return true;
}
private function clickHandler(event:MouseEvent):void
{
// Swap the locations of the first (0) and last (length - 1) items
swapLocations(0, myData.length - 1);
}
public function initData():void {
MyList.dataProvider = myData;
}
]]>