简体   繁体   English

flex4 TextArea中的IUITextField等效项

[英]IUITextField equivalents in flex4 TextArea

I have some flex3 code that uses a TextArea to select a line from a char index: 我有一些使用TextArea从char索引中选择一行的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);

I'd like to upgrade this to flex4's TextArea, but I'm not sure what the flex4 equivalents of the IUITextField methods are (getLineIndexOfChar, getLineOffset, getLineLength). 我想将其升级到flex4的TextArea,但是我不确定IUITextField方法的flex4等效项是什么(getLineIndexOfChar,getLineOffset,getLineLength)。

Can someone point me to some docs for these methods? 有人可以指出我一些使用这些方法的文档吗?

Here is a simple application which illustrates how to select text line with Spark TextArea using TLF and its TextFlow : 这是一个简单的应用程序,它说明了如何使用TLF及其TextFlow使用Spark TextArea选择文本行:

<?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>

All that you need is located in textFlow_selectionChangeHandler() method. 您所需的全部位于textFlow_selectionChangeHandler()方法中。 After determining char position we extracted TextFlowLine for this position and then selected it. 确定字符位置后,我们为此位置提取了TextFlowLine ,然后选择了它。 To test this code just click somewhere in your TextArea . 要测试此代码,只需单击TextArea某个位置。

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM