I want to set the items order that are in an array Collection and bind with a combo-box.
here is my code
[Bindable]private var langList:ArrayCollection = new ArrayCollection([{label:"Englis"},{label:"Urdu"},{label:"Arabic"},{label:"Spanish"}]);
protected function cbm_creationCompleteHandler(event:FlexEvent):void
{
for(var i:int =0; i< langList.length; i++)
{
if(langList[i].label == 'Urdu')
{
cbm.setChildIndex(cbm.getChildAt(i), 0);
break;
}
}
}
<s:ComboBox id="cbm" x="258" y="113" dataProvider="{langList}" creationComplete="cbm_creationCompleteHandler(event)"/>
when i try to run it the following exception throw by the compiler
RangeError: Error #2006: The supplied index is out of bounds.
Be careful,
ComboBox::getChildAtwon’t return the list item, you shouldn’t access the children of a Flex a component, this is a skin matter.If you want to change the elements’ order you must do it in the dataProvider, this is a data matter.
Since your
langListisBindable, the combobox will be automatically updated.