3/3/2011 3:31:16 AM
Title:
Menu in flex
Hi all,
On mouse over of a link, i open a menu like
optionsMenu = Menu.createMenu(this,menuDataProvider,false);
optionsMenu.y = event.stageY;
optionsMenu.x = event.stageX
optionsMenu.show();
Now i want to hide the menu as soon as the user moves out of menu(like the one happening in menubar).
i tried adding listener for rollout event for the link, but it dint work.
can any1 help me out??
3/3/2011 10:15:15 AM
hi,
you can use the following code for hiding a menu on rollout. You can add a rollover listener to your base container so that when the mouse is moved out of menu it fires the mouseOver event of that container and hide it. See this example to hide menu control on mouseout of the menu in flex or flash builder
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" >
<mx:Script>
<![CDATA[
import mx.controls.Menu;
// Create and display the Menu control.
var myMenu:Menu;
private function showMenu(evt:Event):void {
myMenu = Menu.createMenu(null, menuData, false);
myMenu.labelField="@label";
//show and set the position of menu to below button
myMenu.show(evt.target.x, evt.target.y+evt.target.height);
}
protected function canvas1_mouseOverHandler(event:MouseEvent):void
{
if(myMenu){
//hide menu on roll over of container canvas
myMenu.hide()
}
}
]]>
</mx:Script>
<!-- Define menus here -->
<mx:XML format="e4x" id="menuData">
<root>
<menuitem label="MenuItem 1" >
<menuitem label="SubMenuItem a" enabled="False"/>
<menuitem label="SubMenuItem b"/>
</menuitem>
</root>
</mx:XML>
<!-- This button will create menu on rollover and click -->
<mx:Canvas x="0" y="0" width="264" height="263" backgroundColor="#FFFFFF" mouseOver="canvas1_mouseOverHandler(event)">
<mx:Button id="myButton" label="Open Menu" click="showMenu(event)" mouseEnabled="true" x="35" y="52"/>
</mx:Canvas>
</mx:Application>