actionscript-3apache-flexflex4flex4.5flex4.6

Show the submenu on mouse over instead of mouse click in MenuBar in Flex 4.6


I am working in Flex 4.6 web application. I have a menubar when i click on that submenu is being open after that it works on mouse over. Now the problem is I want it on mouse over when i over the mouse on menubar submenu should open not onclick. How can i do it. Please give me your advice.

Thanks Bikrant Singh


Solution

  • You can use MOUSE_OVER event this way

        <mx:MenuBar id="menuBar" creationComplete="onMenuComplete(event)" />
    
    
    
        private function onMenuComplete(event:FlexEvent) {
            menuBar.addEventListener(MouseEvent.MOUSE_OVER, onMenuRollOver, true);
    
        }
    
        private function onMenuRollOver(event:MouseEvent):void {
            if (event.target is IMenuBarItemRenderer && menuBar.selectedIndex == -1) {
                var index:int = IMenuBarItemRenderer(event.target).menuBarItemIndex;
                menuBar.selectedIndex = (index == 0) ? 1 : 0;
            }
        }
    

    But if you want to hide it too, you should use MOUSE_OUT event