FLEX的menubar用外部xml做数据源.

mxml:
 1 <? xml version = " 1.0 "  encoding = " utf-8 " ?>
 2 < mx:Application xmlns:mx = " http://www.adobe.com/2006/mxml "  layout = " absolute "  creationComplete = " cargaMenu.send(); " >
 3      < mx:HTTPService id = " cargaMenu "  showBusyCursor = " true "  method = " POST "  url = " http://localhost/flex/menu.xml "  useProxy = " false "  result = " httpResult(event) "  resultFormat = " e4x " >
 4      </ mx:HTTPService >
 5 < mx:Script >
 6      <! [CDATA[
 7     import mx.rpc.events.ResultEvent;
 8     [Bindable]
 9     public  var  datos:XMLList;
10     [Bindable]
11     private  var  listaMenu:XML;
12     [Bindable]
13     private  var  tipText:String;
14     private  function  httpResult(event:ResultEvent): void
15      {
16        //var listaMenu:XML = event.result as XML;
17        listaMenu= event.result as XML;
18        //datos = new XMLList(listaMenu.Menuitem);
19    }

20     import mx.events.MenuEvent;
21     private  function  menuHandler(event:MenuEvent): void    {   
22                  tipText=event.item.@data;
23            }

24     ]] >
25 </ mx:Script >
26      < mx:HRule x = " 0 "  y = " 85 "  width = " 100% " />
27      < mx:Label x = " 21 "  y = " 18 "  text = " EHAI "  width = " 131 "  height = " 67 "  fontSize = " 36 "  fontWeight = " bold "  color = " #ffffff "  alpha = " 0.96 "  enabled = " true " />
28      < mx:MenuBar x = " 19 "  y = " 98 "  labelField = " @label "  dataProvider = " {listaMenu} "  itemRollOver = " menuHandler(event); "  showRoot = " false "  textDecoration = " underline "  fontSize = " 14 "  fontWeight = " bold " ></ mx:MenuBar >
29      < mx:Canvas x = " 160 "  y = " 9 "  width = " 627 "  height = " 68 " >
30          < mx:Image x = " 5 "  y = " 5 "  width = " 70 "  height = " 58 " />
31          < mx:Label x = " 95 "  y = " 7 "  fontSize = " 12 "  text = " {tipText} "  width = " 522 "  height = " 61 " />
32      </ mx:Canvas >
33 </ mx:Application >
34
XML:
<? xml version="1.0" encoding="gb2312" ?>
< mymenu  label ="all" >
    
< menuitem  label ="软件介绍"  data ="软件介绍软件介绍软件介绍软件介绍软件介绍软件介绍软件介绍软件介绍软件介绍软件介绍软件介绍软件介绍软件介绍软件介绍软件介绍" />
    
< menuitem  label ="主要功能"  data ="主要功能主要功能主要功能主要功能主要功能主要功能主要功能主要功能主要功能主要功能主要功能主要功能主要功能主要功能主要功能" />
    
< menuitem  label ="使用方法一"  data ="使用方法一使用方法一使用方法一使用方法一" />
    
< menuitem  label ="使用方法二"  data ="使用方法二使用方法二使用方法二使用方法二使用方法二" />
    
< menuitem  label ="关于我们"  data ="关于我们关于我们关于我们关于我们" />
    
< menuitem  label ="Menu6"  data ="top6" />
    
< menuitem  label ="Menu7"  data ="top7" />
    
< menuitem  label ="Menu8"  data ="top8" />
    
< menuitem  label ="Menu9"  data ="top9" />
    
< menuitem  label ="Menu10"  data ="top10" />
</ mymenu >

你可能感兴趣的:(Flex)