G’day folks - I ran into an interesting problem while constructing an interactive applet today. It requires reaction to keyboard presses/releases, so I set up the appropriate listener to the stage. It also involves transitioning between different screens and I handle this by adding/removing instances of the sub-screens to the DisplayList of the stage.
Now, here comes the interesting part: from my Control class in reaction to a SWITCH_SCREENS Event:
[AS]removeChild(firstSubScreen);
addChild(secondSubScreen);[/AS]
This script, of course, flawlessly changes the display over to the desired state, but it has the added bonus effect of causing a full stop to all keyboard reaction until I clicked on the screen somewhere.
After a whole lot of playing around and logic following, I finally traced the problem. The stage was listening for keys and was receiving them because firstSubScreen had focus and was on the DisplayList. Once firstSubScreen was removed from that display list the KEY_DOWN Events no longer made it up to the stage.
I found a workaround:
[AS]removeChild(firstSubScreen);
addChild(secondSubScreen);
stage.focus = stage;
//stage.focus = secondSubScreen causes the yellow tab target rectangles to show up[/AS]
This gets rid of the keyboard interactivity delay flawlessly. I guess the question I have is whether or not this is the best way to go about this kind of thing? Is there a better, more intuitive way, to go about it?