标题中几乎描述了我的问题。只是一些细节.. 我正在创建一个自定义组件(基于 ComboBox)并覆盖一些基本方法。最近我发现当我以百分比而不是固定宽度设置它的宽度时,它的行为很奇怪。它倾向于不断调用该commitProperties
方法并最终失败。当我将它的宽度设置为固定值时 - 一切都像魅力一样。我缺少什么来实现?这是一些代码..
override protected function commitProperties():void {
super.commitProperties();
//some stuff ...
TextInput(textInput).setSelection(cursorPosition, cursorPosition);
if (cursorPosition == textInput.text.length || cursorPosition == 0) {
TextInput(textInput).horizontalScrollPosition = (cursorPosition == 0) ? 0 : textInput.width;
}
}
在这里,textInput.width
在这两种情况下都正确返回了计算值。而且,仅针对一个案例,如果需要:
override protected function measure():void {
super.measure();
measuredWidth = 160;
}
我不确定是否需要其他东西..请问是否需要。提前致谢 :)