Skip to main content
Participant
September 21, 2009
Question

getCharIndexAtPoint alternative?

  • September 21, 2009
  • 1 reply
  • 1271 views

Halp!  I'm new to the TLF, I've spent about 45 minutes digging through the docs but it's not clear to me how to map a mouse position over to the underlying character position, in the convetional TextField this was done via TextField.getCharIndexAtPoint(x,y);

I did see a getCharacterAtIndex(index) but I don't know how to get that index first.

This topic has been closed for replies.

1 reply

Adobe Employee
September 23, 2009

Indeed we have not published an equivalent public API for this.

The best API we have right now is the SelectionManager method computeSelectionIndexInContainer.  It has this signature.

        static tlf_internal function computeSelectionIndex(textFlow:TextFlow, target:Object, currentTarget:Object, localX:Number,localY:Number):int

localX and localY are in target's coordinate space.  Generally if you can set target and currentTarget to the container that should give good results.

Hope that helps,

Richard

November 3, 2009

Hi Rdermer,

Can you please help me out, how to do the same?

I am also in need to get the indices from the co-ordinates.

Actually I need the cursor to blink when the user right click as it does for left click.

So if I get way to get character indices from the points, then it will be helpful for me.

Thanks in advance.

November 4, 2009

The following method seems to work as long as you have a MouseEvent (which means it probably won't work for your right-click). Please note I just wrote this yesterday and haven't fully tested.


private function getCharIndex(event:MouseEvent)

{

     //get the textLine that was clicked on

     var textLine:TextLine = event.target as TextLine;


     if (textLine)

     {

          //get the index of the atom that was clicked within the line

          var atomIndex:int = textLine.getAtomIndexAtPoint(event.stageX,event.stageY);

          textLine.flushAtomData(); //allows atom data to be gc'd


          //add the line start index to the atomindex to get the absolute character index that was clicked

          var charIndex:int = TextFlowLine(textLine.userData).absoluteStart + atomIndex;


          return charIndex;

     }

     return -1;

}