Search code examples
actionscript-3apache-flexflex4flex3flex4.5

How to prevent the opening of pop-up submenu of mx:MenuBar (Flex) during its mouseOver/rollOver events?


Im using a mx:MenuBar component with xml data to bring a menu. The basic behaviour as I see is, initially on clicking the top level menu item (i.e on the horizontal bar), the pop-up sub menu opens. Then without clicking anywhere, if I mouse over / roll over on the horizontal menu bar, the pop-up sub menus of the other top level menus opens up.

This behaviour seems to be inconsistent. The pop-up sub menus should open either on click of any top level menu item (horizontal menu bar) or only on mouse over / roll over of the menu bar items.

I want the pop-up submenus to open only on click of the top level menu (horizontal menu bar). So I added event handlers for mouseOver as well as rollOver events (don't know which event actually gets generated on hovering over the horizontal menu bar). In the event handlers, I called the event.preventDefault() method to prevent the default behaviour(i.e opening of pop-up sub menus). But, nothing works. I felt like, I don't have control over it.

Could anyone say how to suppress the default behaviour and open the pop-up submenus only on click event of the menu bar.


Solution

  • You could use "monkey patching" to redefine the behaviour of the MenuBar class. It is not easy to do it through overriding of the methods, because they are private.

    Here is a working example with an active "view source" property.

    The function to be rewritten is

    private function mouseOverHandler(event:MouseEvent):void
    {
    }
    

    One should delete the code lines, which activate a new menu.