Search code examples
actionscript-3airevent-handlingsoft-keyboard

How to catch pressing "Done" or similar button on soft keyboard in AS3


I found many solutions for this in Java language, but I just cannot find an answer for AS3 (AIR application). Also there is no solution in Adobe help. I'm using StageText and need event to catch when user press "Done" button (or any other defined by returnKeyLabel.

Any advice? I will really appreciate this.


Solution

  • Softkeyboards events on Native text fields are different than using a Flash based TextField (or such) as it created outside of the normal DisplayList heirarchy and thus not have the same event processing available to it.

    The event you are looking for is enter, attach an EventListener to that and you can capture your 'Done'.

    Otherwise you would need to look at using "TextField-based skins" in order to capture every keyDown and keyUp and filter and react within your event handler to only the keys that you are interested in.

    To determine when a user is done with the soft keyboard, you can listen for the FlexEvent.ENTER event on the text input control. The control dispatches this event when the return key is pressed. By listening for the enter event, you can perform validation, change focus, or perform other operations on the recently entered text.

    In some cases, the enter event is not dispatched. This limitation appears on Android devices when you use a soft keyboard on the last text input control on the view. To work around this issue, set the returnKeyLabel property to go, next, or search on the last text input control on the view.

    http://help.adobe.com/en_US/flex/mobileapps/WS82181550ec4a666a39bafe0312d9a274c00-8000.html#WS19f279b149e7481c-51e256961331cc2eae5-8000