I see that you're using spark and not mx. The editable
property I referred to is applicable only to mx based list. In spark, ComboBox extends DropDownListBase
and is editable by default.
The ComboBox
control is a child class of the DropDownListBase
control. Like the DropDownListBase
control, when the user selects an item from the drop-down list in the ComboBox
control, the data item appears in the prompt area of the control.
One difference between the controls is that the prompt area of the ComboBox
control is implemented by using the TextInput
control, instead of the Label
control for the DropDownList
control. Therefore, a user can edit the prompt area of the control to enter a value that is not one of the predefined options.
For example, the DropDownList
control only lets the user select from a list of predefined items in the control. The ComboBox
control lets the user either select a predefined item, or enter a new item into the prompt area. Your application can recognize that a new item has been entered and, optionally, add it to the list of items in the control.
The ComboBox
control also searches the item list as the user enters characters into the prompt area. As the user enters characters, the drop-down area of the control opens. It then and scrolls to and highlights the closest match in the item list.
So ideally, you should be using DropDownList
in this case.
You're getting null error when trying to access textInput
from the constructor because it hasn't been created yet. In mx based controls (Flex-3), you can access it from the creationComplete
handler; I'm not quite sure how to do it for spark based controls.
Update: I think I've figured out how to access skin parts in spark (though you might wanna use the DropDownBox
instead). You have to override the partAdded
method.
override protected function partAdded(partName:String, instance:Object):void
{
super.partAdded(partName, instance);
if (instance == textInput)
{
textInput.editable = false;
}
}
There's one catch though: it may not work in this case. The source code of ComboBox.as says that
the API ignores the visual editable
and selectable
properties
So DropDownList
it is!
Initial answer, posted for mx ComboBox
.
This shouldn't happen as the default value of the editable property is false
.
Try explicitly setting the value to false
from the constructor.
public function CustomCombo() {
super();
this.editable = false;
}