JAVA & FLEX

          一個分享java和flex開發經驗的空間

             :: 首頁 ::  :: 聯系 ::  :: 管理 ::
            26 隨筆 :: 2 文章 :: 44 評論 :: 0 Trackbacks
              在Flex Builder中,如果要加載一個外部的XML是比較簡單的,將絕對路徑或則是相對路徑寫入就可以了。但是如果是一個web的工程,這個問題就顯得比較復雜了,因為這個時候,你得不到文件的絕對和相對路徑,在Flex3中,解決這個問題,有如下兩個方法。

              【一】mx:Model的方式
                
               程序主文件:
               
           1<?xml version="1.0"?>
           2<!-- Simple example to demonstrate the LinkBar control. -->
           3<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
           4    <mx:Script>
           5        <![CDATA[            
           6        ]]>
           7    </mx:Script>
           8    <mx:Model id="catalogService" source="news.xml" /> 
           9    <mx:ArrayCollection id="myXC" source="{catalogService.news}"/> 
          10    <mx:Panel title="TestLinkBarForXML" 
          11        height="323" width="466" horizontalAlign="center"
          12        paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10">
          13   
          14        <mx:Text width="100%" 
          15            text="一個LinkBar的測試"/>
          16
          17        <mx:LinkBar color="#0000FF" fontWeight="bold" dataProvider="{myViewStack}"/>        
          18        
          19        <!-- Define the ViewStack and the three child containers. -->
          20        <mx:ViewStack id="myViewStack" borderStyle="solid" width="100%" height="80%">
          21
          22            <mx:Canvas id="show1" backgroundColor="#FFFFCC" label="顯示一" width="100%" height="100%">
          23            
          24            </mx:Canvas>
          25
          26            <mx:Canvas id="show2" backgroundColor="#CCFFFF" label="顯示二" width="100%" height="100%">
          27            <mx:DataGrid dataProvider="{myXC}"/>
          28            </mx:Canvas>
          29
          30            <mx:Canvas id="show3" backgroundColor="#FFCCFF" label="顯示三" width="100%" height="100%">
          31            </mx:Canvas>
          32        </mx:ViewStack>
          33        
          34    </mx:Panel>
          35    <mx:XML id="myXML" source="news.xml" />
          36  
          37      <mx:Text id="myText"  width="292"/>
          38</mx:Application>
          39
          40

              news.xml文件
           1<?xml version="1.0" encoding="utf-8"?>
           2<main>
           3  <news>
           4     <newsTitle>1-1</newsTitle>
           5     <newsItem>1-2</newsItem>
           6  </news>
           7  <news>
           8     <newsTitle>2-1</newsTitle>
           9     <newsItem>2-2</newsItem>
          10  </news>
          11</main>


          運行后畫面:



              【二】mx:HTTPService的方式

              主程序:
          1<?xml version="1.0"?> 
          2<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" initialize="catalogService.send()"> 
          3    <mx:HTTPService id="catalogService" url="catalog.xml" resultFormat="e4x"/> 
          4    <mx:XMLListCollection id="myXC" source="{catalogService.lastResult.product}"/> 
          5    <mx:Repeater id="r" dataProvider="{myXC}" startingIndex="1"> 
          6        <mx:RadioButton id="Radio" label="{r.currentItem.name}"/> 
          7    </mx:Repeater> 
          8</mx:Application>
          9

             xml文件:
           1<?xml version="1.0"?> 
           2<products> 
           3  <product> 
           4    <name>Name</name> 
           5    <price>Price</price> 
           6    <freeship>Free Shipping?</freeship> 
           7  </product> 
           8  <product> 
           9    <name>Whirlygig</name> 
          10    <price>5</price> 
          11    <freeship>false</freeship> 
          12  </product> 
          13  <product> 
          14    <name>Tilty Thingy</name> 
          15    <price>15</price> 
          16    <freeship>true</freeship> 
          17  </product> 
          18<product> 
          19    <name>Really Big Blocks</name> 
          20    <price>25</price> 
          21    <freeship>true</freeship> 
          22  </product> 
          23</products>

          參考:http://www.flashxm.com/?p=169
          posted on 2008-08-29 16:40 程序人生-天津 閱讀(1273) 評論(0)  編輯  收藏 所屬分類: Flex
          主站蜘蛛池模板: 花垣县| 正镶白旗| 漳浦县| 乐亭县| 左贡县| 普兰县| 广德县| 内丘县| 海盐县| 澎湖县| 淮阳县| 延边| 吉林省| 九龙城区| 龙泉市| 池州市| 安丘市| 罗源县| 洪湖市| 金坛市| 泰来县| 农安县| 蒲城县| 天水市| 彰化市| 定安县| 林周县| 祁东县| 涿州市| 灌阳县| 邮箱| 巴里| 定陶县| 上犹县| 理塘县| 玉屏| 临海市| 桂阳县| 瑞丽市| 新宾| 务川|