views:

62

answers:

2

I have one text box and one combobox.

I want it such that when someone changes the combobox value, the text should change in the text field.

priceText is the name of text box

My code is below; it's not working:

var comboFar:ComboBox = new ComboBox();
addChild(comboFar);

var items2:Array = [
{label:"Arizona", data:"87.97"},
{label:"Colorado", data:"91.97"},
];

comboFar.dataProvider = new DataProvider(items2);

comboFar.addEventListener("change",testFar());

function testFar(event):void {

  priceText.text =event_obj.target.selectedItem.data;

}
A: 

Try this:

priceText.text = (event_obj.target as ComboBox).selectedLabel;
//or
priceText.text = (event_obj.target as ComboBox).selectedItem.label; // replace "label" if there is another label field

But you should use bindings if this is Flex.

Srirangan
Iget this error1136: Incorrect number of arguments. Expected 1. and 1067: Implicit coercion of a value of type void to an unrelated type Function.
Mirage
+1  A: 

hi, I think you should use selectedIndex instead

priceText.text =event_obj.target.selectedIndex.data;

or

priceText.text =event_obj.target.selectedItem.label;

edit: hmm more I think about it...you might have it right, just could you also try doing this as well?

comboFar.addEventListener(Event.CHANGE,testFar());
function testFar(e:Event):void {
  priceText.text =event_obj.target.selectedItem.data;
}
VoodooChild
thanks buddy , it worked
Mirage
great, glad I could help out. which of the suggestions above work?
VoodooChild