Skip to main content
Known Participant
March 23, 2010
Question

How can I detect where an element sits within the flow?

  • March 23, 2010
  • 1 reply
  • 1938 views

I know I can get the position as a number of characters in from the root but specifically I need to detect exactly where my element sits within the line it is on and in particular if a LINK element object is sat at the start of the line and is not broken.

I know you can set the breakOpportunity property to prevent a link from breaking on a line so can I detect if a link has broken?

Surely there's a way to detect where an element or character of an element sits on a line.

Any help on this would be appreciated. I've been fighting this framework for the last 4 days now ... I need this to work!

🙂

This topic has been closed for replies.

1 reply

Adobe Employee
March 23, 2010

Start with the LinkElement and its owning TextFlow.

var textFlow:TextFlow

var link:LinkElement;

// start and end of the link

var linkStartPos:int = link.getAbsoluteStart();

var linkEndPos:int = linkStartPos+link.textLength;

var textFlowLine:TextFlowLine = textFlow.flowComposer.findLineAtPosition(linkStart);

The textFlowLine has a absoluteStart and a textLength property.  Compare then with the link start/stop pos to see where the link falls on the line

The link may start on this line and end on a following line.

One caveat - when things are out of view TLF will stop composing early.  To force all content to be fully composed and broken into lines use:

textFlow.flowComposer.composeToPosition(textFlow.textLength)

Hope that helps,

Richard

PoobeardAuthor
Known Participant
March 23, 2010

Hey thanks for this. Sounds promising.

The only thing I can think of is that I will need to add the link to the flow first and then if it is on a new line and at the start then I will have to immediately remove it from the flow, add a new paragraph element object and then add the link as a child of the paragraph. Unless I can add the paragraph and then re-parent the link without having to remove it first.

Sounds better than my technique at the moment which is using a fixed width font and trying to calculate when the link hits a new line.

Thanks.

PoobeardAuthor
Known Participant
March 23, 2010

it throws an error here : var textFlowLine:TextFlowLine = textFlow.flowComposer.findLineAtPosition(linkStart);

textFlowLine comes back as null. I'm using a standard TextArea component at the moment to render the flow. Does this suggest that there isn't a flowComposer object instantiated?

I'm going through a huge array of names and composing the textFlow link by link.

Before I attempt to work out the line position and link position etc I am adding the link to the flow and also running : textFlow.flowComposer.composeToPosition(textFlow.textLength);

It's almost as if the flow hasn't been composed. Do I need to setup a listener or something to detect when it is ready?