The simplified code:
//triggered on MouseEvent.MOUSE_DOWN
private function beginDrag(e:MouseEvent):void
{
stage.addEventListener(MouseEvent.MOUSE_MOVE, drag);
stage.addEventListener(MouseEvent.MOUSE_UP, endDrag);
stage.addEventListener(Event.DEACTIVATE, endDrag);
contextMenu.addEventListener(ContextMenuEvent.MENU_SELECT, endDrag);
}
private function drag(e:MouseEvent):void
{
//do stuff
}
private function endDrag(e:Event):void
{
stage.removeEventListener(MouseEvent.MOUSE_MOVE, drag);
stage.removeEventListener(MouseEvent.MOUSE_UP, endDrag);
stage.removeEventListener(Event.DEACTIVATE, endDrag);
contextMenu.removeEventListener(ContextMenuEvent.MENU_SELECT, endDrag);
}
I am using some click-and-drag techniques within my flash code, and I've noticed some loopholes with the MOUSE_UP event:
- it wont be triggered if a context menu is activated while the mouse is still held down.
- it wont be triggered if the window is deactivated (alt+tab or similar)
My question is: What other events can possibly interrupt the MOUSE_UP event and lead to unexpected behavior?
Additionally is there a way to generically catch ContextMenuEvent.MENU_SELECT for all context menus without having to manually add/remove the listeners to each context menu?