Hello all,
I want to show and hide menu on button click. If one a click of a
button, the menu is shown, then on another click of the same button,
the menu should be hidden. I used a flag to implement this but got in
to a problem. The code snippet is shown below:
private var showMenu:Boolean = true;
private var menu:Menu;
//event listener for button to show menu
private function displayMenu(event:MouseEvent):void {
if(!menu){
menu.createMenu(this,menuData);
}
if(showmenu) {
menu.show(event.currentTarget.x - 75, event.currentTarget.y +
event.currentTarget.height + 2);
showMenu = false;
}else {
menu.hide();
showMenu = true;
}
}
i used a flag to show and hide menu on button click. works fine while
clicking on the button. But as we click on outside the button, the
menu gets hidden but the flag is still false. Now i have to click the
same button twice to make menu appear.
I tried to add a listener for MenuEvent.MENU_HIDE and set the falg to
true on the listener. Doing so i ran into another problem. Whenever i
click on the same button after the menu is shown, the listener is
called first which will set the showMenu flag to true. So now the menu
will always be shown on clicking the button to show the menu.
Hope i was able to make myself clear.
Any idea on how to implement show/hide menu on button click.