1 Reply Latest reply on Aug 13, 2010 2:36 AM by smon_ed

    Keyboard focus

    smon_ed Level 1

      Creating an air 2.0 application in flex.


      I am setting some accessibility keyboard shortcuts inot an application but the eventListeners seem to be missing events unless the user clicks inside certain screen instances.


      The method I am using is:


      1.  Create a keyboard shortcuts class which creates listeners and acts upon events.


      2.  Wait for ApplicationComplete before creating an instance of my keyboard class.


      3.  Pass a reference to FlexGlobals.topLevelApplication to the keyboard class: 

      _mainApp = FlexGlobals.topLevelApplication;


      4.  In the keybaord class, set a reference to the stage of the topLevelApplication


      var core:Stage = _mainApp.stage

      core.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);

      core.addEventListener(KeyboardEvent.KEY_UP, keyUp);


      That's a fairly good picture of what I'm doing, I think.


      Any ideas as to how I should be assigning the events so that the key strokes are not missed?  I'm assuming that the focus is changing in some way because clicking into the application causes the events to be recognised again but when I change the screen, the focus is lost again.  I am creating screens dynamically by removing old children/elements and adding template components to items within a ViewStack.  As all this is going on upon the main app stage, I would have thought that the events would be continously recognised.


      Is there a better way for me to set the event listeners?


      Maybe I should be assigning them to somewhere else?


      [ EDIT ]


      It appears that when there is a focus on a screen element (navigation button being a prime example) and then I redraw the screens (this includes redrawing the page templates and also parts of the navigation, obviously the focus is lost (i.e. I remove the screen element which has current focus) and then hitting tab once makes the key detection active again.


      So... I wonder if I need to place a line somewhere which sets focus to a screen element to retain keyboard event focus.