So I am capturing global keypress events, and I want to suppress my action if some component has focus. A quick read of the docs and the FocusManager class looks like the ticket! More specifically, FocusManager::getFocus() looks like exactly the function I need. So I go ahead and call it, only to find it’s not static — I can only call it on a FocusManager object. Which brings to mind: how do I find one? After a bit of searching, I see some sample code that just refers to a variable “focusManager”. I don’t see it defined in the same, so I assume it’s some magic global — I drop that into my code, and it works!
So if you want a global FocusManager, just try “focusManager” and see if that works for you.
Why does that work? Well, after a bit more thought, I consider: Perhaps focusManager is an attribute on the Application class? And maybe the keypress handler function I’m writing in the <mx:script> section of my MXML file is actually a method extending the Application class, meaning all the Application protected attributes are accessible in my function? A quick look at the Application docs, and sure enough, that’s the case. Cool!
This totally helped me just now. I am not sure why it works, either. I saw that UIComponent has a focusManager property…
Anyway, thank you for sharing!
–Geoff