This content has been marked as final. Show 3 replies
This appears to be either a bug with the documentation or in the software. I'll file a report. I'm afraid that leaves you with the work-around.
Thanks Peter - my guess is a bug with the documentation (unfortunately), since the TextField makes no such claim and the TextArea simply delegates to the TextField.
Just for the benefit of anyone else who tries to do the same, my workaround entails listening both to the keyDown and keyUp events. The keyDown event fires when the delete or backspace key is pressed, but the text value is as yet unmodified. On this event (if it's one of those keys), I capture the textField's text value, selectionBeginIndex and selectionEndIndex. On the keyUp event for one of these keys, I reset the textField's text property, and then call setSelection to restore the selection to whatever it had been. This has the unfortunate consequence of seeing the data disappear and then reappear, but it does allow a reasonably encapsulated way of preventing it.
I'm interested if anyone has any suggestions to improve it.
Well... It never is so easy, is it?! If the user presses backspace and holds it down, I don't get an event to react to until they lift the key again. So, it needs to be a little more intelligent than this. In face the keyDown event fires repeatedly if you hold the key down, and the keyUp fires just once when the key is lifted.
Can anyone confirm that the source for flash.text.TextField is unavailable?