开发者

Debugging focus and event propagation in Flex

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?


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.


I've just found out that the following technique may be very helpful in debugging focus issues:

private function handleTextInputFocus(event:FocusEvent):void {
  try {
    throw new Error('test');
  } catch (e:Error) {
    trace(e.getStackTrace());
  }
}

The stack can explain why the text input stole the focus from another component.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜