Flex與后臺交互的4種方法 HTTPService、URLLoader、WebService詳解

          Flex與后臺交互的4種方法 HTTPService、URLLoader、WebService詳解?

          HTTPService


          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="<mx:Script>
          <![CDATA[
          private function initializeHandler(event:Event):void {
          countriesService.send();
          }
          private function changeHandler(event:Event):void {
          statesService.send();
          }
          ]]>
          </mx:Script>
          <!-- 載入純靜態的xml數據 -->
          <mx:HTTPService id="countriesService" url="
          <!-- 載入由php生成的xml數據 -->
          <mx:HTTPService id="statesService" url="
          <!-- 以下標簽就是要發送到服務端的數據了,可以這樣理解:有一個名為country的變量,它的值為花括號{}里的內容 -->
          <mx:request>
          <country>{country.value}</country>
          </mx:request>
          </mx:HTTPService>
          <mx:VBox>
          <!-- 此控件的數據由第一個<mx:HTTPService/>控件接收的內容提供,并且由這個ComboBox控制著第二個ComboBox所要顯示的內容 -->
          <mx:ComboBox id="country" dataProvider="{countriesService.lastResult.countries.country}"
          change="changeHandler(event)" />
          <!-- 下面的ComboBox已經綁定了{statesService.lastResult.states.state},隨它的數據改變而改變 -->
          <mx:ComboBox dataProvider="{statesService.lastResult.states.state}" />
          </mx:VBox>
          </mx:Application>


          URLLoader


          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="
          <mx:Script>
          <![CDATA[
          private var _countriesService:URLLoader;
          private var _statesService:URLLoader;
          private function initializeHandler(event:Event):void {
          _countriesService = new URLLoader();
          _countriesService.addEventListener(Event.COMPLETE, countriesCompleteHandler);
          _countriesService.load(new URLRequest("
          _statesService = new URLLoader();
          _statesService.addEventListener(Event.COMPLETE, statesCompleteHandler);
          XML.ignoreWhitespace = true;
          }
          private function countriesCompleteHandler(event:Event):void {
          var xml:XML = new XML(_countriesService.data);
          country.dataProvider = xml.children();
          }
          private function statesCompleteHandler(event:Event):void {
          var xml:XML = new XML(_statesService.data);
          state.dataProvider = xml.children();
          }
          private function changeHandler(event:Event):void {
          var request:URLRequest = new URLRequest("
          var parameters:URLVariables = new URLVariables();
          parameters.country = country.value;
          request.data = parameters;
          _statesService.load(request);
          }
          ]]>
          </mx:Script>
          <mx:VBox>
          <mx:ComboBox id="country" change="changeHandler(event)" />
          <mx:ComboBox id="state" />
          </mx:VBox>
          </mx:Application>

          ?


          WebService 方法一


          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="
          <mx:Script>
          <![CDATA[
          private function initializeHandler(event:Event):void {
          statesService.getCountries();
          }
          private function changeHandler(event:Event):void {
          statesService.getStates(country.value);
          }
          ]]>
          </mx:Script>
          <mx:WebService id="statesService"
          wsdl="
          <mx:operation name="getCountries" />
          <mx:operation name="getStates" />
          </mx:WebService>
          <mx:VBox>
          <mx:ComboBox id="country"
          dataProvider="{statesService.getCountries.lastResult}" change="changeHandler(event)" />
          <mx:ComboBox dataProvider="{statesService.getStates.lastResult}" />
          </mx:VBox>
          </mx:Application>


          WebService 方法二


          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="
          <mx:Script>
          <![CDATA[
          private function initializeHandler(event:Event):void {
          statesService.getCountries.send( );
          }
          private function changeHandler(event:Event):void {
          statesService.getStates.send( );
          }
          ]]>
          </mx:Script>
          <mx:WebService id="statesService" wsdl="
          <mx:operation name="getCountries" />
          <mx:operation name="getStates">
          <mx:request>
          <country>{country.value}</country>
          </mx:request>
          </mx:operation>
          </mx:WebService>
          <mx:VBox>
          <mx:ComboBox id="country"
          dataProvider="{statesService.getCountries.lastResult}" change="changeHandler(event)" />
          <mx:ComboBox dataProvider="{statesService.getStates.lastResult}" />
          </mx:VBox>
          </mx:Application>

          原文:http://bbs.airia.cn/FLEX/thread-2738-1-1.aspx

          posted on 2009-12-31 14:48 飛熊 閱讀(563) 評論(0)  編輯  收藏 所屬分類: Flex

          <2009年12月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          導航

          統計

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          收藏夾

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 明星| 青铜峡市| 乌兰察布市| 上林县| 溆浦县| 玉山县| 临夏县| 福州市| 伊宁市| 灵璧县| 金寨县| 大庆市| 临泉县| 五莲县| 黔西县| 天祝| 芮城县| 宁阳县| 逊克县| 昌黎县| 大名县| 彭阳县| 镇康县| 崇仁县| 盱眙县| 紫云| 灵宝市| 牡丹江市| 台东县| 板桥市| 武穴市| 正蓝旗| 安龙县| 巴林左旗| 枣阳市| 雅江县| 微博| 明溪县| 铜鼓县| 綦江县| 德钦县|