AIR application slow-down while mouse-over-ing ContextMenu/NativeMenu
I'm building an application for AIR, written in AS3, and sometimes (most of the time), when I move my mouse over the right-click menu (I've tried both ContextMenu and NativeMenu - am currently using NativeMenu because of needed submenus), the Video object slows down significantly (it is showing the image of a local webcam), and the FPS counter also drops (obviously). This happens both while debugging, and while runnning the application after inst开发者_如何学编程alling. It's a real deal breaker, I would really appreciate some help. I've yet to find anything resembling this on the Internet, it's really weird.
This is because the ContextMenu needs to be drawn through Windows GDI (software level) and your Flash video object is beeing rendered through the GPU (of course it could be fixed by Adobe, but as of now they haven't).
The only solution is to pause the video (or remove it from stage) before the ContextMenu appears, by catching ContextMenuEvent.MENU_SELECT on all existing ContextMenu objects (if there are none, add one for each object which inherits InteractiveObject added directly to the stage
).
If you want to resume the video playback, you will have to accept some limitations. Since there is no event on close of a ContextMenu, you need to rely on
- ContextMenuEvent.MENU_SELECT_ITEM (fired by ContextMenuItem, which you create and add to the ContextMenu.customItems array)
- FullScreenEvent (going out and into FullScreen guarantees the ContextMenu was closed)
- Event.DEACTIVATE (Flash will close any context menus if it loses input focus)
- MouseEvent.CLICK - this is not a good idea in some situations (you figure it out for your app) (you could combine this with a semi transparent dark Sprite on top of everything to indicate the necessity of a mouse click for the "cancel" action, and to catch and stop propagation of the click);
In some situations you won't be able to detect the closing of the ContextMenu, such as
- when the user is selecting a built in menu item (not the case with Adobe Air)
- presses keys such as F10 or Escape
- other situations
精彩评论