Skip to main content
Participant
Apr 16, 2010 1:36 PM UTC
Answered

Alternative to getLineText() in Flex4 (spark)?

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 is closed to new replies. Start a new post to keep the conversation going.
robin_briggsCorrect answer
Adobe Employee
Apr 16, 2010 3:46 PM UTC

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
Jun 10, 2010 8:43 PM UTC

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.

Translate
robin_briggsCorrect answer
Adobe Employee
Apr 16, 2010 3:46 PM UTC

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

Translate