Skip to main content
Inspiring
January 13, 2010
Question

How can i get the cursor position in a text?(in x,y coordinates)

  • January 13, 2010
  • 1 reply
  • 2042 views

Hi

Im trying to open a menu at the current position of the cursor.

i can get the cursor position in characters, but i need the (x,y) coordinates for the blinking cursor.

(the (x,y) coordinates of the character before the cursor would be fine too)

Anyone knows how to get it?

Thanks for help

This topic has been closed for replies.

1 reply

Adobe Employee
January 15, 2010

There is a function you can call, not one of the pubicly documented ones, but you can find it in the source, called GeometryUtils.getHighlightBounds(). You pass in the textFlow, and a start and end position, and it returns an array with the textLine and a bounds rect in coordinates relative to the TextLine, for each line the TextRange crosses over. In your case, that would be just one line since you have just one character. You can translate that into container coordinates by calling textLine.localToGlobal, and back to container coordinates (if that's what you wanted) by calling container.globalToLocal.

Note that this will return the highlight area that you would see if the selection covered the range of text.

Hope this helps,

- robin

Participating Frequently
January 30, 2010

I can't seem to find this is the newest release of flex (flex 4.0.0.13875). Is this answer still valid? Thanks!

Adobe Employee
February 2, 2010

Yes. See flashx.textLayout.utils.GeometryUtil.getHighlightBounds. I see it here:

http://opensource.adobe.com/svn/opensource/flex/sdk/trunk/frameworks/projects/textLayout/src/flashx/textLayout/utils/GeometryUtil.as

Hope this helps,

- robin