Return to Snippet

Revision: 42321
at March 3, 2011 06:14 by msdevweb


Initial Code
private function findIndex(dp:ArrayCollection, prop:String, what:String ):int {
		for(var k:int=0; k<dp.length; k++) {
			if(String(dp.getItemAt(k)[prop])==what) return k;
		}
	return -1;
}

Initial URL


Initial Description
Used to retriev a index, for example to select a item on a combobox with the arrayCollection as dataProvider.

Usage:
comboBoxNames.selectedIndex = findIndex(arrayColNames, "field_on_array_collection", "value_to_compare_with_field_in_array_coll");

Returns the arrayCollection index that corresponds to compared item. If item is not found on arrayCollection it return -1.

Initial Title
Find Index on ArrayCollection for ComboBox Selection

Initial Tags
search, find

Initial Language
ActionScript 3