PDA

View Full Version : Find out where on TextField context menu appears



IQAndreas
February 4th, 2010, 09:28 AM
I want users to be able to right click on a certain line in the text field, and I don't want to go through the hassle and extra memory and coding involved in breaking up the field.

If the user has not selected the textField yet, right clicking will set the "caretIndex" to the correct value, however, if the field is in focus when they right click, the carrotIndex will not display the correct value, but will display the selection value.

How can I detect which line/character was right clicked? Is it even possible to get the coordinates of the right click without needing to resort to detecting MOUSE_MOVE and updating some sort of global value each time?


http://www.kirupa.com/forum/images/icons/carrot.gif

_kp
February 4th, 2010, 09:56 AM
Is it even possible to get the coordinates of the right click without needing to resort to detecting MOUSE_MOVE and updating some sort of global value each time?

Display objects have a mouseX and mouseY value, there is no need to listen to mouse moves. I don't know if it's possible to listen to right mouse button clicks, however I think the contextmenu dispatches an event when opened.
Maybe there's still some other way without need to calculate from pixel values.

IQAndreas
February 4th, 2010, 10:23 AM
Display objects have a mouseX and mouseY value, there is no need to listen to mouse moves. I don't know if it's possible to listen to right mouse button clicks, however I think the contextmenu dispatches an event when opened.
:smacks head: Thank you, of course! How could I be so silly and forget.

The ContextMenuEvent does not extend MouseEvent or contain properties that tell where the mouse is, HOWEVER, the properties "mouseX" and "mouseY" of the textField will point to the last location of the mouse, which will be exactly where the ContextMenu appeared.


Once the mouse position is found, the following two functions will help fine the line or character that I need:
getCharIndexAtPoint() (http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/text/TextField.html#getCharIndexAtPoint%28%29)
getLineIndexAtPoint() (http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/text/TextField.html#getLineIndexAtPoint%28%29)


I never before realized how powerful the TextField class really is, and how so many useful properties are often taken for granted!