Skip to main content
Participant
May 29, 2012
Question

Process space bar or enter key on Spark ButtonBar

  • May 29, 2012
  • 1 reply
  • 1085 views

The examples I have read on using ButtonBar have focused mainly on trapping the change event and taking action based on the selected index. However, in my Flex 4.6 application, it seems that pressing the space bar or enter key on a button does not trigger the change event.  For accessibility purposes, I need to handle either the space bar or enter key to allow the user to choose a button via the keyboard.  If I simply put the click="clickhandler(event)" on the ButtonBar, I seem to get results; however, I haven't figured out how to identify which button was activated in this handler. Also, due (I believe to bubbling) I'm getting the handler triggered by any Button click event inside the containers managed by the ButtonBar.

Any example code on taking action on a ButtonBar based on space bar or enter key would be appreciated!

This topic has been closed for replies.

1 reply

esdebon
Inspiring
May 29, 2012

click="clickhandler(event)" is MXML not Action Script 3

//Adds event listener to the stage.

  stage.addEventListener(KeyboardEvent.KEY_DOWN, detectKey);

  //Traces the keycode, keylocation, shiftkey and altkey.

  function detectKey(event:KeyboardEvent):void {

       trace("The keypress code is: " + event.keyCode);

       trace("The keyLocation is: " + event.keyLocation);

       trace("The shiftKey is: " + event.shiftKey);

        trace("The altKey is: " + event.altKey);

  }

Spacebar = 32

http://www.ilike2flash.com/2010/02/detect-key-press-in-actionscript-3.html

http://www.dakmm.com/?p=272

Participant
May 29, 2012

Thanks a bunch! I’ll give this a try. This same logic will probably resolve another defect I need to fix in the app which is shortcut keys to help the screen reader user navigate more easily.