我正在以编程方式填充一个文本字段,并在添加新文本时滚动到MaxScrollh,以便用户可以看到文本的进展。这样做很好,直到我单击textfield,它将scrollh设置回0,并将插入符号放在文本中的等效位置。
textField.setSelection( text.length, text.length ); //sets the caretIndex/selection to the end
textField.scrollH = textField.maxScrollH; //scrolls to max
这是更新textfield文本属性时用于滚动的代码。我尝试在textfield的click事件中添加一个监听器,它在某种程度上起作用,但会导致可见的跳转。
override protected function createChildren() : void
{
super.createChildren();
textField.addEventListener(MouseEvent.CLICK, handleTextFieldClick, false, 0, true);
}
protected function handleTextFieldClick(event:MouseEvent):void
{
textField.scrollH = currentTextFieldScrollPosition; //stored scrollH value
trace(textField.scrollH);
}
我的猜测是有一个滚动位置正在计算或存储在我找不到的地方。