我正在使用Flex Builder中的Adobe AIR和Google Maps API进行实验。问题是,我正在制作NativeMenu,并且想知道,当舞台全屏时,如何将“全屏”项目的标签更改为“退出全屏”?
如果您在代码中看到任何可以/应该写得更好的内容,请告诉我们;)
这是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
height="600"
width="700"
minHeight="100"
minWidth="100"
showStatusBar="false"
title="Gmaps 0.002"
>
<maps:Map
xmlns:maps="com.google.maps.*"
id="map"
mapevent_mapready="onMapReady(event)"
width="100%"
height="100%"
url=""
key=""
/>
<mx:Button id="fullscreenButton" click="toggleFullScreen()"/>
<mx:Script>
<![CDATA[
import com.google.maps.LatLng;
import com.google.maps.Map;
import com.google.maps.MapEvent;
import com.google.maps.MapType;
import com.google.maps.MapMouseEvent;
import com.google.maps.controls.MapTypeControl;
import com.google.maps.controls.ZoomControl;
import com.google.maps.controls.PositionControl;
import flash.display.NativeMenu;
import flash.display.NativeMenuItem;
import flash.events.Event;
import mx.core.Window;
import flash.display.StageDisplayState;
private function onMapReady(event:Event):void {
map.setCenter(new LatLng(59.908165,10.742719), 14, MapType.NORMAL_MAP_TYPE);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
function keyDownHandler(event:KeyboardEvent):void {
if (event.keyCode == 70) {
toggleFullScreen();
}
}
createMenu();
map.enableScrollWheelZoom();
map.enableContinuousZoom();
map.enableControlByKeyboard();
systemManager.stage.addEventListener(FullScreenEvent.FULL_SCREEN, fullScreenHandler);
map.addEventListener(MapMouseEvent.ROLL_OVER, function(event:MapMouseEvent):void {
map.addControl(new ZoomControl());
map.addControl(new PositionControl());
map.addControl(new MapTypeControl());
});
map.addEventListener(MapMouseEvent.ROLL_OUT, function(event:MapMouseEvent):void {
map.removeControl(new ZoomControl());
map.removeControl(new PositionControl());
map.removeControl(new MapTypeControl());
});
}
private function createMenu():void{
var mainMenu:NativeMenu = new NativeMenu();
var fullscreenMenu:NativeMenuItem = new NativeMenuItem("Fullscreen");
var maximizeMenu:NativeMenuItem = new NativeMenuItem("Maximize");
var restoreMenu:NativeMenuItem = new NativeMenuItem("Restore");
var separatorA:NativeMenuItem = new NativeMenuItem("A", true);
var closeMenu:NativeMenuItem = new NativeMenuItem("Close");
fullscreenMenu.addEventListener(Event.SELECT, handleMenuClick);
maximizeMenu.addEventListener(Event.SELECT, handleMenuClick);
restoreMenu.addEventListener(Event.SELECT, handleMenuClick);
closeMenu.addEventListener(Event.SELECT, handleMenuClick);
mainMenu.addItem(fullscreenMenu);
mainMenu.addItem(maximizeMenu);
mainMenu.addItem(restoreMenu);
mainMenu.addItem(separatorA);
mainMenu.addItem(closeMenu);
//fullscreenMenu.enabled = false;
//fullscreenMenu.label = "Test";
this.contextMenu=mainMenu;
}
private function handleMenuClick(e:Event):void{
var menuItem:NativeMenuItem = e.target as NativeMenuItem;
if(menuItem.label == "Fullscreen") toggleFullScreen();
if(menuItem.label == "Maximize") this.maximize();
if(menuItem.label == "Restore") this.restore();
if(menuItem.label == "Close") this.close();
}
private function fullScreenHandler(evt:FullScreenEvent):void {
if (evt.fullScreen) {
//fullscreenMenu.label = "Test";
} else {
}
}
private function toggleFullScreen():void {
try {
switch (systemManager.stage.displayState) {
case StageDisplayState.FULL_SCREEN_INTERACTIVE:
systemManager.stage.displayState = StageDisplayState.NORMAL;
break;
default:
systemManager.stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
break;
}
} catch (err:SecurityError) {
// ignore
}
}
]]>
</mx:Script>
</mx:WindowedApplication>
答案 0 :(得分:1)
为了将标签更改为NativeMenu,您可以尝试使用
yourNativeMenu.getItemAt(0).label="new_label";
其中getItemAt(0)
返回NativeMenu中的第一项