1 Reply Latest reply on Jan 15, 2007 11:44 AM by FlightGuy

    text deletion events

    jaimon_jaimon Level 1
      hi,
      i am extending the TextInput control, i have managed to catch the text typing events...

      my question is:
      how can i catch the text deletion (delete and backspace keys) events ??

      thanks,
      jaimon
        • 1. Re: text deletion events
          FlightGuy Level 1
          Listen for the "keyDown" event, and the examine the event.charCode for a value of 8 or 127 respectively.

          If you want to prevent the backspace/delete, it's not so easy - you cannot prevent propagation of the keyDown event. Here's what I do (not pretty, but it works):

          var caretOffset:uint = textField.selectionEndIndex;
          textField.setSelection(caretOffset, caretOffset);
          textField.replaceSelectedText(' ');
          if (event.charCode == 127)
          textField.setSelection(caretOffset, caretOffset);

          This works by putting a space in the position that's about to be deleted or backspaced over, so the end effect after the deletion is unchanged. Because backspace also moves us back, we move the cursor to after the inserted space.

          Tim