1

我正在以编程方式填充文本字段并在添加新文本时滚动到 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);
}

我的猜测是有一个滚动位置正在计算或存储在我找不到的某个地方。

4

2 回答 2

1

flex TextInput 设置 textField 的选择:

/**
 *  @private
 *  Gets called by internal field so we draw a focus rect around us.
 */
override protected function focusInHandler(event:FocusEvent):void
{
    if (event.target == this)
        systemManager.stage.focus = TextField(textField);

    var fm:IFocusManager = focusManager;

    if (editable && fm)
    {
        fm.showFocusIndicator = true;
        if (textField.selectable &&
            _selectionBeginIndex == _selectionEndIndex)
        {
            textField.setSelection(0, textField.length);
        }
    }

    [...]

在我的组件中覆盖它可以解决这个问题:

    override protected function focusInHandler(event:FocusEvent):void
    {
        super.focusInHandler(event);
        textField.scrollH = currentTextFieldScrollPosition;
    }
于 2009-09-20T19:47:02.447 回答
1

事实证明,您需要为带有 UIScrollbar 的窗口创建一个 onclick 处理程序,然后为其添加一个焦点输出事件侦听器,将 onclick 时的滚动条位置传递给焦点。 ActionScript 3:在 Flash embed 中失去焦点时保持 textarea UIscrollbar 位置

于 2010-10-25T16:00:13.367 回答