views:

30

answers:

1

The link elements I'm talking about are single words, so they are not wrapped inside the container, which means that they should have a single bounding rectangle. But how do I go about finding this rectangle? I'm familiar with Flex3 but don't know enough about the new Text Layout Engine in Flex4.

Can someone help me please? Thanks!

A: 

After some digging, a colleague found a reference to a similar question on one of the Adobe forums. Here is an implementation of the algorithm proposed in that post (thanks Noam!):

private function getElementPosition(link:LinkElement):Point {
    if (!link) return null;
    var absoluteStart:int = link.getAbsoluteStart();
    var textLine:TextLine = link.getTextFlow().flowComposer.findLineAtPosition(absoluteStart).getTextLine(true);
    var rect:Rectangle = textLine.getAtomBounds(textLine.getAtomIndexAtCharIndex(absoluteStart));
    return textLine.localToGlobal(new Point(rect.x, rect.height+rect.y));
}

I've tested this and it seems to do the job. Just wanted to share it for the sake of anybody else interested in the same problem in the future.

Roy Sharon