当我不为 ViewNavigatorApplication 应用 skinClass 时,ViewMenuItems 工作正常,但是当我将自定义皮肤应用于 ViewNavigator 时,ViewMenuItems 不会出现。
我的 Main.mxml 文件包含
<?xml version="1.0" encoding="utf-8"?>
<s:ViewNavigatorApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" firstView="views.MainHomeView" skinClass="skins.CustomApplicationSkin">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
</s:ViewNavigatorApplication>
CustomApplicationSkin 的代码是
<?xml version="1.0" encoding="utf-8"?>
<s:Skin name="CustomApplicationSkin"
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
>
<fx:Metadata>
<![CDATA[
[HostComponent("Main")]
]]>
</fx:Metadata>
<s:states>
<s:State name="normal" />
<s:State name="disabled" />
</s:states>
<s:BitmapImage width="100%" height="100%" source="@Embed('/assets/background.jpg')"/>
<s:Group id="contentGroup" width="100%" height="100%" minWidth="0" minHeight="0" />
<s:ViewNavigator id="navigator" width="100%" height="100%" />
</s:Skin>
MainHomeView.mxml 的代码
<?xml version="1.0" encoding="utf-8"?>
<!-- components\mobile\views\ViewMenuHome.mxml -->
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
title="Home">
<fx:Script>
<![CDATA[
// The event listener for the click event.
private function itemClickInfo(event:MouseEvent):void {
switch (event.currentTarget.label) {
case "Add" :
myTA.text = "Add selected";
break;
case "Cancel" :
myTA.text = "Cancel selected";
break;
case "Delete" :
myTA.text = "Delete selected";
break;
case "Edit" :
myTA.text = "Edit selected";
break;
case "Search" :
myTA.text = "Search selected";
break;
default :
myTA.text = "Error";
}
}
]]>
</fx:Script>
<s:viewMenuItems>
<s:ViewMenuItem label="Add" click="itemClickInfo(event);" />
<s:ViewMenuItem label="Cancel" click="itemClickInfo(event);"/>
<s:ViewMenuItem label="Delete" click="itemClickInfo(event);"/>
<s:ViewMenuItem label="Edit" click="itemClickInfo(event);"/>
<s:ViewMenuItem label="Search" click="itemClickInfo(event);"/>
</s:viewMenuItems>
<s:VGroup paddingTop="10" paddingLeft="10">
<s:TextArea id="myTA" text="Select a menu item"/>
<s:Button label="Open Menu"
click="mx.core.FlexGlobals.topLevelApplication.viewMenuOpen=true;"/>
<s:Button label="Close Menu"
click="mx.core.FlexGlobals.topLevelApplication.viewMenuOpen=false;"/>
</s:VGroup>
</s:View>
请协助。