I am creating a menu this way :
myMenu = Menu.createMenu( null, myMenuXMLListCollection, false );
and then showing it with :
myMenu.popup( 10, 10 );
but the menu doesn't disappear automatically when i click somewhere outside the menu.
Listen for the SandBoxMouseEvent . MOUSE_UP_SOMEWHERE on the sandbox root. You can get the Sandbox root using SystemManager . getSandboxRoot
So, add your event listener, something like this:
systemManager.getSandBoxRoot.addEventListener(SandboxMouseEvent.MOUSE_UP_SOMEWHERE, myMouseUpHandler);
And then in your event handler, just check to see if the target is the menu and if not hide the menu:
protected function myMouseUpHandler(event:SandboxMouseEvent):void{
if(event.target != myMenuInstance){
myMenuInstance.visible = false;
// or whatever other action you wish to take to hide the menu.
}
}
This is the general approach that the Flex ComboBox uses to hide the drop down menu on mouse click.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.