我编程填充一个文本字段和滚动到maxScrollH作为新的文本被添加,以便用户可以看到文本的进展。这工作得很好,直到我点击文本字段,它设置scrollH回到0,并将插入符号在同等位置的文本。

textField.setSelection( text.length, text.length ); //sets the caretIndex/selection to the end
textField.scrollH = textField.maxScrollH; //scrolls to max

这是我使用时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);
}

我的猜测是,有被计算出的滚动位置或存储在某处,我无法找到。

有帮助吗?

解决方案

柔性的TextInput设置文本字段的选择:

/**
 *  @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;
    }

其他提示

原来你需要为具有UIScrollBar窗口的onclick处理程序,然后为其添加一个焦点了事件侦听器在的onclick的焦点时通过滚动条的位置。 的ActionScript 3:维护文本区域的UIScrollBar位置在闪光焦点丢失嵌入

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top