views:

66

answers:

1

I have a custom TitleWindow component that is registered to listen for keyboard events from the user (so that esc closes the window, enter saves, etc.). However, in my testing I've found a couple cases where my keyboard event handlers don't fire.

My best guess as to why this is happening is that there is some child component somewhere that has stolen focus and is stopping the keyboard events from propagating. Unfortunately, due to the large number of components in my TitleWindow, I have no good way of knowing who has stolen the focus.

My question then is, are there any good tips / techniques / tools for debugging focus issues and event propagation in Flex? Basically, I need something that will tell me who has the focus at any given time and who's handling an event at any given time... is that possible?

+1  A: 

Utilizing Focus Manager you can call getFocus() and you will receive the IFocusManagerComponent back that currently has focus.

From there, you can determine which type of object has stolen focus by using flash.utils.getQualifiedClassName() and act accordingly.

As for event handling at any given time, you want to compare e.target with e.currentTarget.

Tegeril
Thanks, Tegeril, by using FocusManager I was able to discover who had stolen the focus and was consuming the keyboard events, problem solved! One thing I'll mention about your solution for event handling is that because my handlers weren't being called, I had no place to breakpoint and check e.target and e.currentTarget. It's a very tricky situation when you control neither the item dispatching the event nor the item handling the event!
Dan
Ah, very good point about the events. I can't think of a way to capture non-bubbling events if they fire on objects you aren't listening to, maybe someone can provide some input and enlighten both of us :)
Tegeril