Java代码
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
  3. xmlns:s="library://ns.adobe.com/flex/spark"
  4. xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
  5. <fx:Script>
  6. <![CDATA[
  7. import mx.events.MenuEvent;
  8. private function menuClickHandle(e:MenuEvent):void{
  9. switch(e.label){
  10. case "submenu1":currentState="index1";break;
  11. case "submenu2":currentState="index2";break;
  12. case "submenu3":currentState="index3";break;
  13. case "submenu4":currentState="index4";break;
  14. case "submenu5":currentState="index5";break;
  15. }
  16. }
  17. ]]>
  18. </fx:Script>
  19. <s:states>
  20. <s:State name="index1" />
  21. <s:State name="index2" />
  22. <s:State name="index3" />
  23. <s:State name="index4" />
  24. <s:State name="index5" />
  25. </s:states>
  26. <fx:Declarations>
  27. <!-- 将非可视元素(例如服务、值对象)放在此处 -->
  28. <fx:XMLList id="myXMLList">
  29. <item id="menu1">
  30. <item id="submenu1" type="radio" groupName1="one" />
  31. <item id="submenu2" type="radio" groupName2="one" />
  32. </item>
  33. <item id="menu2" />
  34. <item id="menu3" />
  35. <item id="menu4" >
  36. <item id="submenu3" type="radio" groupName="two" />
  37. <item id="submenu4" type="radio" groupName="two" selected="true" />
  38. <item id="submenu5" type="radio" groupName="two" />
  39. </item>
  40. </fx:XMLList>
  41. </fx:Declarations>
  42. <mx:MenuBar y="24" id="myMenubar" dataProvider="{myXMLList}" labelField="@id" width="293" horizontalCenter="0" change="menuClickHandle(event)" change.index2="menuClickHandle(event)"></mx:MenuBar>
  43. <s:Group id="group1" includeIn="index1" x="{myMenubar.x}" y="{myMenubar.y+myMenubar.height}">
  44. <s:Rect width="{myMenubar.width}" height="248" alpha="0.5">
  45. <s:fill>
  46. <mx:SolidColor color="#000000" />
  47. </s:fill>
  48. </s:Rect>
  49. </s:Group>
  50. <s:Group id="group2" includeIn="index2" x="{myMenubar.x}" y="{myMenubar.y+myMenubar.height}">
  51. <s:Rect width="{myMenubar.width}" height="248" alpha="0.5">
  52. <s:fill>
  53. <mx:SolidColor color="#f5e532" />
  54. </s:fill>
  55. </s:Rect>
  56. </s:Group>
  57. <s:Group id="group3" includeIn="index3" x="{myMenubar.x}" y="{myMenubar.y+myMenubar.height}">
  58. <s:Rect width="{myMenubar.width}" height="248" alpha="0.5">
  59. <s:fill>
  60. <mx:SolidColor color="#bdf531" />
  61. </s:fill>
  62. </s:Rect>
  63. </s:Group>
  64. <s:Group id="group4" includeIn="index4" x="{myMenubar.x}" y="{myMenubar.y+myMenubar.height}">
  65. <s:Rect width="{myMenubar.width}" height="248" alpha="0.5">
  66. <s:fill>
  67. <mx:SolidColor color="#d731f5" />
  68. </s:fill>
  69. </s:Rect>
  70. </s:Group>
  71. </s:Application>