PDA

View Full Version : How to fill combobox?


jarmanje
09-26-2008, 01:02 PM
Hello.

How can i fill a combobox based on the value of a var.

This is what i'm trying to do, but this code is all wrong:

<mx:ComboBox editable="false" enabled="true"><mx:ArrayCollection>
<mx:Object label="Main stage" data="stage1"/>
<mx:Object label="2nd stage" data="stage2"/>
<mx:Object label="3rd stage" data="stage3"/>
</mx:ArrayCollection>

Currenctlyselected value of combox = callfunctioninas3();
</mx:ComboBox>



//code in <!CDATA{

private function callfunctioninas3():void
{
if (currentOrder.order=="stage1") {
//set value of combox to "Main stage"
} else if (currentOrder.order=="stage2") {
//set value of combox to "2nd stage"
} else if (currentOrder.order=="stage3") {
//set value of combox to "3rd stage"
} else {
//set the combox to nothing
}
}



Sorry for my amateur coding, but it shows how i'd like to do it!

Thanks a lot for any help

monkey4Hire
09-29-2008, 04:01 PM
Hi,



<mx:ComboBox dataProvider="{choices}" change="itemChanged(event)"/>
<mx:ArrayCollection id="choices">
<mx:Object label="Main stage" data="stage1"/>
<mx:Object label="2nd stage" data="stage2"/>
<mx:Object label="3rd stage" data="stage3"/>
</mx:ArrayCollection>
<mx:Script>
<![CDATA[
import mx.events.ListEvent;

private function itemChanged(event:ListEvent):void
{
// Do logic here
}
]]>
</mx:Script>





Currently selected combo box value is in event.currentTarget.selectedItem.data or .label

s_light
09-29-2008, 04:08 PM
www.s-light.cn

:p helpyourself please!