[英]Flex extending ComboBox
I created a class CustomCombo.as
that extends ComboBox
. 我创建了一个扩展
ComboBox
的类CustomCombo.as
。 What is happening is that the CustomCombo
combobox is showing as being editable. 发生的事情是
CustomCombo
组合框显示为可编辑。 I do not want this and I cant find the properties to set the editable
to false
. 我不想要这个,我无法找到将
editable
设置为false
的属性。
I also tried setting the combobox's textInput.editable
control to false
, but to no avail. 我也尝试将组合框的
textInput.editable
控件设置为false
,但无济于事。
Any help would be greatly appreciated. 任何帮助将不胜感激。
CustomCombo.as
package custom {
import spark.components.ComboBox;
public class CustomCombo extends ComboBox {
public function CustomCombo() {
super();
// this.editable = false; //<-- THIS DOESNT WORK ***Access of possibly undefined property editable through a reference with static type custom:CustomCombo
// this.textInput.editable = false; //<-- THIS DOESNT WORK ***Cannot access a property or method of a null object reference
}
}
}
After rummaging through the Flex 4 API I found that they suggest to use the DropDownList
control. 通过Flex 4 API翻找后,我发现他们建议使用
DropDownList
控件。 From what I can see is that they removed the editable
property from the ComboBox
control in Flex 4, but I may be wrong. 从我可以看到他们从Flex 4中的
ComboBox
控件中删除了editable
属性,但我可能错了。
I implemented DropDownList
and that solved my problem. 我实现了
DropDownList
,这解决了我的问题。
I see that you're using spark and not mx. 我看到你使用的是火花而不是mx。 The
editable
property I referred to is applicable only to mx based list. 我引用的
editable
属性仅适用于基于mx的列表。 In spark, ComboBox extends DropDownListBase
and is editable by default. 在spark中, ComboBox扩展了
DropDownListBase
,默认情况下是可编辑的。
The
ComboBox
control is a child class of theDropDownListBase
control.ComboBox
控件是DropDownListBase
控件的子类。 Like theDropDownListBase
control, when the user selects an item from the drop-down list in theComboBox
control, the data item appears in the prompt area of the control.与
DropDownListBase
控件一样,当用户从ComboBox
控件的下拉列表中选择项时,数据项将显示在控件的提示区域中。One difference between the controls is that the prompt area of the
ComboBox
control is implemented by using theTextInput
control, instead of theLabel
control for theDropDownList
control.控件之间的一个区别是
ComboBox
控件的提示区域是使用TextInput
控件实现的,而不是DropDownList
控件的Label
控件。 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.例如,
DropDownList
控件仅允许用户从控件中的预定义项列表中进行选择。 TheComboBox
control lets the user either select a predefined item, or enter a new item into the prompt area.ComboBox
控件允许用户选择预定义项目,或在提示区域中输入新项目。 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.当用户在提示区域中输入字符时,
ComboBox
控件还会搜索项目列表。 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. 理想情况下,在这种情况下你应该使用
DropDownList
。
You're getting null error when trying to access textInput
from the constructor because it hasn't been created yet. 尝试从构造函数访问
textInput
时,您会收到null错误,因为它尚未创建。 In mx based controls (Flex-3), you can access it from the creationComplete
handler; 在基于mx的控件(Flex-3)中,您可以从
creationComplete
处理程序访问它; 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). 更新:我想我已经想出如何访问spark中的皮肤部分(尽管你可能想要使用
DropDownBox
)。 You have to override the partAdded
method. 您必须覆盖
partAdded
方法。
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
ComboBox.as的源代码说明了这一点
the API ignores the visual
editable
andselectable
propertiesAPI忽略可视的
editable
和selectable
属性
So DropDownList
it is! 所以它是
DropDownList
!
Initial answer, posted for mx ComboBox
. 初步回答,发布于mx
ComboBox
。
This shouldn't happen as the default value of the editable property is false
. 这不应该发生,因为editable属性的默认值为
false
。
Try explicitly setting the value to false
from the constructor. 尝试从构造函数显式将值设置为
false
。
public function CustomCombo() {
super();
this.editable = false;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.