Skip to main content
Known Participant
March 29, 2010
Question

How can I get the global position in pixels of a FlowElement within its container Sprite

  • March 29, 2010
  • 1 reply
  • 755 views

I'm trying to get the position of a FlowElement within its container. I can get the TextFlowline, the start and end position of the element within the Flow and from that I can get the container. I now need to work out how many lines that element sits within the container, work out the top and left of the element in pixels so I can move my viewport to that position.

Any ideas? Is there a localToGlobal position for the element?

This topic has been closed for replies.

1 reply

PoobeardAuthor
Known Participant
March 29, 2010

I can get the bounds of the TextFlowLine within the container : var rect:Rectangle = textFlowLine.getBounds();

All I need to do now is get the bounds of the element within the line and I'm there. unfortunately there is no getBounds for the FlowElement object.

PoobeardAuthor
Known Participant
March 29, 2010

I realise that this is difficult to achieve because the element I want to find may run over multiple lines. I can find out where the required element starts within the line by doing this :

var linkPositionOnLine:int = linkStart-textFlowLine.absoluteStart;

... this tells me how many characters in on the line I will find the start of the element. Are there metrics available that I can use to go through each of these characters within the line and return the overall width? Would need to take into account the spacing between the characters too I guess.

March 29, 2010

Our flashx.textLayout.compose.TextFlowLine is a TLF object that keeps track of certain properties on a flash.text.engine.TextLine, which is the display object. Given a TextFlowLine you can call getTextLine to get the TextLine object, which has a getAtomBounds method to return a rectangle bounding a single atom on the line. An atom can be a character, graphic element or combination of characters that are being combined to make one complex character.

So if you're looking for the bounds of the first atom (which in most cases is the first character) on a TextFlowLine, you'd make this call:

myTextFlowLine.getTextLine().getAtomBounds(0)