My point was that if the button always says "Show Menu", why would the user 
expect it to hide the menu?

From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of 
prashant194
Sent: Sunday, November 30, 2008 9:34 PM
To: [email protected]
Subject: [flexcoders] Re: problem implementing show/hide menu on button click


Hi Alex,

I think that will not work either. If i click on the same button,
first the MENU_HIDE will be called then the click listener will be
called. If i change the flag on MENU_HIDE, the click listener will
again show the menu. Let me show you the code i used:

private function displayMenu(event:MouseEvent):void {
if(!menu) {
menu= Menu.createMenu(this,settingsMenuData);

menu.addEventListener(MenuEvent.MENU_HIDE, onMenuHide);
}
if(!isMenuShowing) {
menu.show(event.currentTarget.x, event.currentTarget.y);
}
}

private function onMenuHide(event:MenuEvent):void {
isMenuShowing = false;
}

did i miss something?

--- In [email protected]<mailto:flexcoders%40yahoogroups.com>, Alex 
Harui <[EMAIL PROTECTED]> wrote:
>
> Usually you don't need a "hide" phase to the button. Once shown,
clicking anywhere will hide it. Only set the flag to false on MENU_HIDE.
>
> From: [email protected]<mailto:flexcoders%40yahoogroups.com> 
> [mailto:[email protected]<mailto:flexcoders%40yahoogroups.com>]
On Behalf Of prashant194
> Sent: Sunday, November 30, 2008 2:08 AM
> To: [email protected]<mailto:flexcoders%40yahoogroups.com>
> Subject: [flexcoders] problem implementing show/hide menu on button
click
>
>
> 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.
>

Reply via email to