Posted By

msdevweb on 03/03/11


Tagged

search index find arrayCollection


Versions (?)

Find Index on ArrayCollection for ComboBox Selection


 / Published in: ActionScript 3
 

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

Usage: comboBoxNames.selectedIndex = findIndex(arrayColNames, "fieldonarraycollection", "valuetocomparewithfieldinarraycoll");

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

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

Report this snippet  

You need to login to post a comment.