0

我使用 Flash buider 4.6,我喜欢为我的 AIR 应用程序模仿 Mac Os 应用程序菜单。
在这个菜单中,我想添加:关于我的应用程序、隐藏我的应用程序和隐藏其他。

对于第一个命令,没问题,但我不知道如何继续使用 AS3 命令进行隐藏和隐藏其他命令。

你能帮我解决这个问题吗?

谢谢

请参阅下面的示例

<?xml version="1.0" encoding="utf-8"?>

<fx:Script>

    <![CDATA[
        import mx.controls.Alert;

        // Preserve the original menus for the purposes of this demo (MacOS)
        private var oldMenu:NativeMenu = NativeApplication.nativeApplication.menu;
        private var newWindow:NativeWindow;

        private function showMenus():void
        {
            //For Windows
            if (NativeWindow.supportsMenu)
            {
                // On Windows, we need to create a window so we can add a menu (Tour de Flex has no Chrome)
                var options:NativeWindowInitOptions = new NativeWindowInitOptions(); 
                options.systemChrome = NativeWindowSystemChrome.STANDARD; 
                options.transparent = false; 
                newWindow = new NativeWindow(options); 
                newWindow.width = 500; 
                newWindow.height = 100; 
                newWindow.title = "Demonstration of Native Menus for Windows applications";
                newWindow.menu = createMenu();
                newWindow.alwaysInFront = true; 
                newWindow.activate();    

                msg.text = "Window Menu (Windows) - A NativeWindow has been created to demonstrate the menu";
            }

            // On MacOS, replace the current app menu with our new menu
            if (NativeApplication.supportsMenu)
            {
                // In 
                NativeApplication.nativeApplication.menu = createMenu();
                msg.text = "Application Menu (MacOS) - The Application menu has been replaced with demo menu";
            }
        }

        private function createMenu():NativeMenu
        {
            var menu:NativeMenu = new NativeMenu();
            var menuItem1:NativeMenuItem = new NativeMenuItem("Takeoff");
            menuItem1.submenu = createTakeoffMenu();
            menuItem1.addEventListener(Event.SELECT, selectHandler);
            menu.addItem(menuItem1);

            var menuItem2:NativeMenuItem = new NativeMenuItem("Landing");
            menuItem2.submenu = createLandingMenu();
            menuItem2.addEventListener(Event.SELECT, selectHandler);
            menu.addItem(menuItem2);
            return menu;
        }

        private function createTakeoffMenu():NativeMenu
        {
            var menu:NativeMenu = new NativeMenu();
            var takeoffItem1:NativeMenuItem = new NativeMenuItem("Gear Up");
            takeoffItem1.checked = true;
            takeoffItem1.addEventListener(Event.SELECT, selectHandler);
            menu.addItem(takeoffItem1);
            var takeoffItem2:NativeMenuItem = new NativeMenuItem("Retract Flaps");
            takeoffItem2.checked = true;
            takeoffItem2.addEventListener(Event.SELECT, selectHandler);
            menu.addItem(takeoffItem2);
            return menu;
        }

        private function createLandingMenu():NativeMenu
        {
            var menu:NativeMenu = new NativeMenu();
            var landingItem1:NativeMenuItem = new NativeMenuItem("Gear Down");
            landingItem1.addEventListener(Event.SELECT, selectHandler);
            menu.addItem(landingItem1);
            var landingItem2:NativeMenuItem = new NativeMenuItem("Extend Flaps");
            landingItem2.addEventListener(Event.SELECT, selectHandler);
            menu.addItem(landingItem2);
            var landingItem3:NativeMenuItem = new NativeMenuItem("Shutdown");
            landingItem3.addEventListener(Event.SELECT, selectHandler);

            var shutdownMenu:NativeMenu = new NativeMenu();


            // Create submenu
            var shutdownItem1:NativeMenuItem = new NativeMenuItem("Turn off avionics");
            shutdownItem1.addEventListener(Event.SELECT, selectHandler);
            shutdownMenu.addItem(shutdownItem1);

            var shutdownItem2:NativeMenuItem = new NativeMenuItem("Pull Mixture");
            shutdownItem2.addEventListener(Event.SELECT, selectHandler);                
            shutdownMenu.addItem(shutdownItem2);            

            var shutdownItem3:NativeMenuItem = new NativeMenuItem("Turn off Mags");
            shutdownItem3.addEventListener(Event.SELECT, selectHandler);                
            shutdownMenu.addItem(shutdownItem3);

            // Add submenu to parent menu
            landingItem3.submenu = shutdownMenu;

            menu.addItem(landingItem3);
            return menu;
        }


        private function selectHandler(event:Event):void 
        {
            // Put code here to handle the selection
            Alert.show(event.target.label);
        }

        // Cleanup when we leave
        private function revertMenus():void {
            if (NativeApplication.supportsMenu) {
                NativeApplication.nativeApplication.menu = oldMenu;
            }
            if (NativeWindow.supportsMenu) {
                newWindow.close();
            }
        }
    ]]>
</fx:Script>
<s:VGroup horizontalCenter="0" top="10">
    <s:Label id="msg" width="100%" color="#FFFFFF" textAlign="center"/>
    <s:Button label="Show Menus" click="showMenus()"/>
    <s:Button label="Reset" click="revertMenus()"/>    
</s:VGroup>

还有截图

在此处输入图像描述

4

2 回答 2

1

我找到了解决方案

 // Assign application menu (Mac OS X)

        if(NativeApplication.supportsMenu){
            var appMenu:NativeMenu = NativeApplication.nativeApplication.menu;
            while (appMenu.items.length > 1)
            {
                appMenu.removeItemAt(appMenu.items.length - 1);
            }

            appMenu.addSubmenu(creerMenuFichier(),"Fichier");
            appMenu.addSubmenu(creerMenuEdition(),"Edition");
            appMenu.addSubmenu(creerMenuModule(),"Modules");
            appMenu.addSubmenu(creerMenuActions(),"Actions");
            appMenu.addSubmenu(creerMenuHelp(),"Aide");

            // Attach event listener routine to root menu
            appMenu.addEventListener(Event.SELECT, dispatchMenuCommand);

        }

代替

                NativeApplication.nativeApplication.menu = createMenu();
于 2012-04-27T10:52:50.740 回答
0

这些选项由 OS X 提供,您无需执行任何操作即可获得这些选项。

于 2012-04-26T15:06:10.957 回答