代码之家  ›  专栏  ›  技术社区  ›  Joel Hooks

actionscript 3 textfield scrollh属性在单击时设置为0

  •  1
  • Joel Hooks  · 技术社区  · 15 年前

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

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

    2 回复  |  直到 14 年前
        1
  •  1
  •   Joel Hooks    15 年前

    flex textfinput设置文本字段的选择:

    /**
     *  @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;
        }
    
        2
  •  1
  •   Community CDub    8 年前

    结果发现,您需要为带有uiscrollbar的窗口生成onclick处理程序,然后为它添加一个focus out事件侦听器,该侦听器在onclick指向焦点时传递滚动条位置。 ActionScript 3: maintaining textarea UIscrollbar position on loss of focus in flash embed