Skip to main content
Participant
April 16, 2010
Answered

Alternative to getLineText() in Flex4 (spark)?

  • April 16, 2010
  • 2 replies
  • 614 views

We need to build a function that places a linefeed after each displayed line wrap. This is to save the entered text the same way it is displayed in the editor for its later reproduction as a PDF.

Now as getLineText() hasn't been included in the new components and we can't switch back to MX we have to retrieve every single line of characters a different way.

I'd like to know if there is an alternative to the MX getLineText() in Flex4 Spark with the RichEditableText, or at least a way to combine functions that will reach the same result.

This topic has been closed for replies.
Correct answer robin_briggs

If you want to find out which text went in which lines, start by getting the TextFlow from the RichEditableText. Once you have it, see that it has a "flowComposer". Given the flowComposer, and assuming that the text is validated in Flex (e.g., updateDisplayList has been called), you can iterate the lines like this:

for (var i:int = 0; i < flowComposer.numLines; i++)

{

     var line:TextFlowLine = flowComposer.getLineAt(0);

     var lineStart:int = line.absoluteStart;

     var lineEnd:int = line.absoluteStart + line.textLength;

}

I don't know what you are doing to export the text back into PDF, but this should give you the information about where the lines end, so you can incorporate that into your export function.

Hope this helps,

- robin

2 replies

Participant
June 10, 2010

Hi, I did have the same problem, when I did migrate my app flex3 to flex4 but after a long time this is my solution

var activePos:int = codeArea.selectionActivePosition;

Alert.show("line: "+codeArea.textFlow.getChildAt( codeArea.textFlow.findChildIndexAtPosition(activePos) ).getText() );

Where the codeArea is a RichEditableText, but is applicable to all textFlow,

Regards.

robin_briggsCorrect answer
Adobe Employee
April 16, 2010

If you want to find out which text went in which lines, start by getting the TextFlow from the RichEditableText. Once you have it, see that it has a "flowComposer". Given the flowComposer, and assuming that the text is validated in Flex (e.g., updateDisplayList has been called), you can iterate the lines like this:

for (var i:int = 0; i < flowComposer.numLines; i++)

{

     var line:TextFlowLine = flowComposer.getLineAt(0);

     var lineStart:int = line.absoluteStart;

     var lineEnd:int = line.absoluteStart + line.textLength;

}

I don't know what you are doing to export the text back into PDF, but this should give you the information about where the lines end, so you can incorporate that into your export function.

Hope this helps,

- robin