我使用Flash buider 4.6,我喜歡模擬我的AIR應用程序的Mac Os應用程序菜單。
在此菜單中,我想添加:關於MyAPP,隱藏MyApp和隱藏其他。MAcOS上的本地菜單:如何實現「隱藏」並隱藏其他
對於第一個命令,沒問題,但我不知道如何繼續使用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>
而一個屏幕截圖
不行,必須添加此命令。請參閱屏幕截圖。謝謝 – Flex60460 2012-04-26 16:11:05
這是在我做的應用程序的情況下,不替換菜單,也許嘗試並附加到它而不是替換? – grapefrukt 2012-04-27 07:24:30
你如何添加而不是替換? – Flex60460 2012-04-27 09:41:17