In ActionScript 3.0, DataProvider.getItemIndex() method is not working properly. It mostly returns -1, as an indicator of ‘Item not found’ in the DataProvider.
Following code illustrates the problem ::
import fl.controls.ComboBox;
import fl.data.DataProvider;
var cb:ComboBox = new ComboBox();
this.addChild(cb);
var dp:DataProvider = new DataProvider();
dp.addItem({label:”Ashvin Savani”});
dp.addItem({label:”Naresh Khokhaneshiya”});
dp.addItem({label:”Jignesh Dodiya”});
dp.addItem({label:”Alpesh Vaghasiya”});
cb.dataProvider = dp;
//get index of item ‘Naresh Khokhaneshiya’
var index:int = dp.getItemIndex({label:”Naresh Khokhaneshiya”});
//following line outputs :: index : -1, which is totally wrong
trace(“index : ” + index);
//set the item selected
cb.selectedIndex = index;
Naresh Khokhaneshiya
Posted by misoa on June 20, 2008 at 11:49 am
Hello. You can see next topic: http://www.actionscript.org/forums/showthread.php3?t=149781. It really works!
Posted by Naresh Khokhaneshiya on June 20, 2008 at 12:49 pm
@misoa,
You are right but that needs actual reference to the item object which mostly we don’t have. We have correct values in the item object to compare but it checks the reference and hence not working.