PDA

View Full Version : [Object Object] error for combobox.selectedItem


salim_designer
08-27-2007, 11:38 AM
I can't understand where am I making the mistake.

Here is my code:

import fl.controls.ComboBox;
import fl.controls.Label;

var myComboBox:ComboBox = new ComboBox();
myComboBox.prompt = "Please select an item...";
myComboBox.addItem({label:"Item 1"});
myComboBox.addItem({label:"Item 2"});
myComboBox.addItem({label:"Item 3"});
myComboBox.addItem({label:"Item 4"});
myComboBox.width = 150;
myComboBox.move(10, 10);
myComboBox.addEventListener(Event.CHANGE, changeHandler);
addChild(myComboBox);

var myLabel:Label = new Label();
myLabel.autoSize = TextFieldAutoSize.LEFT;
myLabel.move(myComboBox.x + myComboBox.width + 10, myComboBox.y);
addChild(myLabel);

function changeHandler(event:Event):void {
myLabel.text = "selectedItem:" + myComboBox.selectedItem;
trace(myComboBox.selectedItem)
}

I should get the label of the selected Item but I am getting [Object object].

Can anybody tell me where is my mistake?

Thanks :)

LuisVirgil
01-15-2008, 03:00 PM
try trace(myComboBox.selectedItem.label) instead of trace(myComboBox.selectedItem)