How to disable default browser navigation with Space in Flex

雨燕双飞 提交于 2019-12-12 03:00:52

问题


I have defined a keyboard shortcut that uses space. After I have pressed the shortcut two things happen: some random navigation in my app and also the code in my eventHandler from the keyboard shortcut.

I found THIS table with browser keyboard shortcuts and obviously space sometimes is used for navigation. So is there a way to stop the navigation with space in Flex, because eating the spacebar button doesn't seem to work:

  FlexGlobals.topLevelApplication.addEventListener(KeyboardEvent.KEY_DOWN,
                                                     ignoreSpaceNavigation);

  private static function ignoreSpaceNavigation(event:KeyboardEvent):
     event.preventDefault();
     event.stopImmediatePropagation();
  }

So any ideas how to stop the navigation? (I really want to use space for that keyboard shortcut!)


回答1:


Try to set event listener on a stage and use capture

stage.addEventListener(KeyboardEvent.KEY_DOWN, ignoreSpaceNavigation, true);


来源:https://stackoverflow.com/questions/24205150/how-to-disable-default-browser-navigation-with-space-in-flex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!