R – TextField() – filter backspace key away with event listener

actionscript-3apache-flexflex3

How to prevent a specific key such as backspace key functioning from TextField editable field, preventDefault does not seem to work:

public function handleEvents(evt:KeyboardEvent):void {
 if (evt.type == KeyboardEvent.KEY_UP) {
 if (evt.keyCode==8){
   evt.preventDefault () ;
  }
}

Best Answer

I recommend listening for the KEY_DOWN event if anything, but likely that won't work either. IIRC these type of events are a bit special and you can't really stop them. What I suspect you need to do is to store a copy of the text and whenever you detect a change you don't like just set it back to your stored version.

Related Topic