开发者

Need help with changing text with combobox state change

I have one text box and one combobox.

I want it such that when someone changes the combobox valu开发者_如何学JAVAe, 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;

}


In addEventListener, you are calling testFunc(). You need to pass function's reference instead like below:

import flash.events.Event;
comboFar.addItem({label:"Arizona", data:"87.97"});
comboFar.addItem({label:"Colorado", data:"91.97"});
comboFar.selectedIndex=0;
comboFar.addEventListener(Event.CHANGE,testFunc);
function testFunc(evt:Event):void {
    priceText.text =evt.target.selectedItem.data; // 87.97
    // or
    priceText.text =evt.target.selectedItem.label; // Arizona
}


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.


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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜