Skip to main content
Participant
June 5, 2010
Question

findChildIndexAtPosition and child boundaries

  • June 5, 2010
  • 1 reply
  • 489 views

The docs for TextFlow.findChildIndexAtPosition contains the following comment:

Given a relative text position, find the index of the first child FlowElement that contains the relative position. More than one child can contain relative position because of zero length FlowElements.

Examine the children to find the FlowElement that contains the relative position. The supplied relative position is relative to this FlowElement.

I do not understand the meaning or implication of "zero length FlowElements". Nor does the example fragment show any indication of "examining the children".

In a possibly related vein, I don't understand why the parentRelativeEnd of one child equals the parentRelativeStart of the next child; and the method findChildIndexAtPosition finds the preceding child if the position is that duplicated value, even though the text at that position is contained in the second child, not the first.In fact, the position lies one beyond the boundary.

This topic has been closed for replies.

1 reply

Adobe Employee
June 7, 2010

The length of a FlowElement is the number of Unicode characters in it. A zero length FlowElement has no characters in it. Usually, these will be automatically removed, unless it was created from mxml. In that case, the zero width FlowElements are preserved because they could be bound to a Flex variable. In a flow that has zero width elements, there may be more than one leaf node element at the same position, or text index.

"Examining the children" has to do with the fact that findChildIndexAtPosition is returning a child within the FlowElement (in this case the TextFlow). Let's say the flow contains three paragraphs. findChildIndexAtPosition will return the paragraph that contains the position. You could also call findChildIndexAtPosition on one of the paragraphs, and get the span that contains the position. In this case, the position is considered relative to the paragraph. So position 0 would refer to the first character in the paragraph, even if the paragraph is not the first one in the TextFlow.

Let's say I have a SpanElement that contains a single character. It starts at position 0, and ends at (or extends up to) position 1. The next span starts at position 1. The last character in the FlowElement will start at the element.textLength -1.

I hope this explains a little better how it works,

- robin

Participant
June 7, 2010

I still don't understand why findChildIndexAtPosition(x) returns the index

of the child element that ends at x-1 rather than the child

that begins at x.