azmiman
10-06-2008, 05:23 AM
Hi everyone
I have a combobox:
<mx:ComboBox x="2" y="2" id="itemComboBox" change="displayItem(event)"/>
The value of the combobox comes from RemoteObject function call (asp c#). Basically the c# method will read a table from a database and return a DataTable which consist of list of itemCode and itemName. Here is how I call the method "listItem" in the RemoteObject:
private function init():void
{
item = new RemoteObject( "GenericDestination" );
item.source="class.data.getData";
item.listItem.addEventListener( FaultEvent.FAULT, faultHandler );
item.listItem.addEventListener( ResultEvent.RESULT, itemHandler );
item.listItem();
}
// Populate item combobox
private function itemHandler( event:ResultEvent ):void
{
itemList = new ArrayCollection(event.result as Array);
itemComboBox.dataProvider = itemList;
itemComboBox.labelField = "itemName";
}
// Display the value of selected item
private function displayItem(event:Event):void
{
var itemName:String = event.currentTarget.selectedItem.@label;
Alert.show( itemName, "Show Item" );
}
Now, I manage to populate the combobox correctly ie. list of item names are displayed accordingly. My problem is when I want to display the value of the selectedItem of the combobox(itemComboBox) upon item selection. It gives error " Property @label not found on Object and there is no default value."
My questions:
1. How do I access the selectedItem value from the combobox?
2. How do I assign the itemName as the label and itemCode as the data?
Thanks in advance.
I have a combobox:
<mx:ComboBox x="2" y="2" id="itemComboBox" change="displayItem(event)"/>
The value of the combobox comes from RemoteObject function call (asp c#). Basically the c# method will read a table from a database and return a DataTable which consist of list of itemCode and itemName. Here is how I call the method "listItem" in the RemoteObject:
private function init():void
{
item = new RemoteObject( "GenericDestination" );
item.source="class.data.getData";
item.listItem.addEventListener( FaultEvent.FAULT, faultHandler );
item.listItem.addEventListener( ResultEvent.RESULT, itemHandler );
item.listItem();
}
// Populate item combobox
private function itemHandler( event:ResultEvent ):void
{
itemList = new ArrayCollection(event.result as Array);
itemComboBox.dataProvider = itemList;
itemComboBox.labelField = "itemName";
}
// Display the value of selected item
private function displayItem(event:Event):void
{
var itemName:String = event.currentTarget.selectedItem.@label;
Alert.show( itemName, "Show Item" );
}
Now, I manage to populate the combobox correctly ie. list of item names are displayed accordingly. My problem is when I want to display the value of the selectedItem of the combobox(itemComboBox) upon item selection. It gives error " Property @label not found on Object and there is no default value."
My questions:
1. How do I access the selectedItem value from the combobox?
2. How do I assign the itemName as the label and itemCode as the data?
Thanks in advance.