Управление меню Flex - Нажмите кнопку, и отобразится меню. Как я могу нажать эту кнопку во второй раз и скрыть это меню?

Вы используете Timer Class в пакете java.util и планируете timertask, чтобы закрыть заставку через некоторое время, скажем, 2 минуты или задача завершена.

 final Processing nc = new Processing();
 nc.setVisible(true);
 Timer timer = new Timer():
 TimerTask task = new TimerTask() {
      public void run() { 
          nc.setVisible( false );
          // to do disposing nc
      }
 };
 timer.schedule( task, 1000 * 3 ); // dispose the processing frame after 3 minutes
1
задан Matthew Flaschen 20 June 2010 в 02:17
поделиться

1 ответ

//Declare menu as an instance variable instead of a local var
private var myMenu:Menu;

//var to store menu status
private var isMenuVisible:Boolean

//Create the Menu control. call this from the creationComplete of the 
//application or the Component that it is part of.
private function createMenu():void 
{
    var myMenu:Menu = Menu.createMenu(null, myMenuData, false);
    myMenu.labelField="@label";
    //menu fires an event when it is hidden; listen to it.
    myMenu.addEventListener(MenuEvent.MENU_HIDE, onMenuHidden);
}
private function onMenuHidden(e:MenuEvent):void
{
    /*
    menuHide event fired whenever the menu or one of its submenus
    are hidden - makes sure it was indeed the main menu that was hidden
    I don't have compiler handy to test this, so if for 
    some reason comparing myMenu with e.menu doesn't work,
    try if(e.target == myMenu) instead; 
    And please let me know which one works via comment :)
    */

    if(e.menu == myMenu)
       isMenuVisible = false;
}
//call this from button's click 
private function toggleMenu():void
{
    if(isMenuVisible)
        myMenu.hide();
    else
        myMenu.show();
}
2
ответ дан 2 September 2019 в 23:39
поделиться
Другие вопросы по тегам:

Похожие вопросы: