0

私は Flash buider 4.6 を使用しており、AIR アプリケーション用に Mac OS のアプリケーション メニューを模倣するのが好きです。
このメニューに追加したいのは、About MyAPP、Hide MyApp、Hide Others です。

最初のコマンドは問題ありませんが、AS3 コマンドで hide と hide other を実行する方法がわかりません。

この問題を解決するのを手伝ってくれませんか。

ありがとう

以下の例を参照してください

<?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 に答える