【问题标题】:IUITextField equivalents in flex4 TextAreaflex4 TextArea 中的 IUITextField 等效项
【发布时间】:2011-04-15 20:15:57
【问题描述】:

我有一些使用 TextArea 从字符索引中选择一行的 flex3 代码:

var tf:IUITextField=ta.mx_internal::getTextField();
var lineIndex:int= tf.getLineIndexOfChar(someCharIndex);
var lineCharIndex:int= tf.getLineOffset(lineIndex);
var lineLength:int= tf.getLineLength(lineIndex);
ta.setSelection(lineCharIndex, lineCharIndex+lineLength);

我想将此升级到 flex4 的 TextArea,但我不确定 IUITextField 方法的 flex4 等效项是什么(getLineIndexOfChar、getLineOffset、getLineLength)。

有人可以为我指出这些方法的一些文档吗?

【问题讨论】:

    标签: actionscript-3 apache-flex flex4 flex3


    【解决方案1】:

    这是一个简单的应用程序,它说明了如何使用 Spark TextArea 使用 TLF 及其 TextFlow 选择文本行:

    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark" 
        xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="init()">
        <fx:Script>
        <![CDATA[
            import flashx.textLayout.compose.TextFlowLine;
            import flashx.textLayout.elements.TextFlow;
            import flashx.textLayout.events.SelectionEvent;
    
            private function init():void
            {
                var textFlow:TextFlow = ta.textFlow;
                textFlow.addEventListener(SelectionEvent.SELECTION_CHANGE, textFlow_selectionChangeHandler);
            }
    
            private function textFlow_selectionChangeHandler(event:SelectionEvent):void
            {
                // Just getting char index
                var selectionStart:int = event.selectionState.absoluteStart;
                var textFlow:TextFlow = ta.textFlow;
                var line:TextFlowLine = textFlow.flowComposer.findLineAtPosition(selectionStart);
                ta.selectRange(line.absoluteStart, line.absoluteStart + line.textLength);
            }
        ]]>
        </fx:Script>
        <s:TextArea width="400" height="200" verticalCenter="0" horizontalCenter="0" id="ta">
            Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor 
            incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco 
            laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate 
            velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, 
            sunt in culpa qui officia deserunt mollit anim id est laborum.      
        </s:TextArea>
    </s:Application>
    

    所有你需要的都位于textFlow_selectionChangeHandler() 方法中。在确定字符位置后,我们为该位置提取TextFlowLine,然后选择它。要测试此代码,只需单击 TextArea 中的某处即可。

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-16
      • 2018-06-25
      • 2015-07-09
      • 2017-10-24
      • 2014-07-04
      • 2010-09-20
      相关资源
      最近更新 更多