2011-04-15 25 views
0

我有一個使用文本區域來選擇從一個字符的索引行一些flex3代碼:IUITextField的等價物在FLEX4文本區

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的文本區,但我不知道IUITextField方法的flex4等價物是什麼(getLineIndexOfChar,getLineOffset,getLineLength)。

有人可以指點我一些文檔的這些方法嗎?

回答

1

下面是一個簡單的應用程序,它說明了如何使用TLF及其TextFlow選擇星火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> 

所有你需要的是位於textFlow_selectionChangeHandler()方法。在確定字符位置後,我們爲此位置提取TextFlowLine,然後選擇它。要測試此代碼,只需點擊TextArea中的某個地方。

希望這會有所幫助!

+0

像一個魅力工作。謝謝! – paleozogt 2011-04-15 21:29:52

+0

不客氣! :) – Constantiner 2011-04-15 21:32:28