سؤال

أنا ملء Textfield برمجيا والتمرير إلى MaxScrollh حيث يتم إضافة النص الجديد، لذلك يمكن للمستخدم رؤية تقدم النص. يعمل هذا بشكل جيد، حتى النقر فوق TextField، الذي يعيد SCROLLH مرة أخرى إلى 0 ويضع Caret في النص في الموضع المكافئ.

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

هذا هو الرمز الذي أستخدمه للتمرير عند تحديث خاصية TextField Text. لقد حاولت إضافة مستمع إلى الحدث Click على TextField، والذي يعمل بطريقة ما، ولكن يسبب قفزة مرئية.

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 Flex اختيار 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;
    }

نصائح أخرى

اتضح أنك بحاجة إلى إنشاء معالج OnClick للنافذة باستخدام UISCrollBar، ثم قم بإضافة مستمع من الأحداث التركيز الذي يمر موقع Scrollbar في وقت تشغيل OnClick إلى التركيز.ActionScript 3: الحفاظ على موضع Textarea Uiscrollbar على فقدان التركيز في فلاش تضمين

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top