Flex 調用WebService

先看看Flex如何調用WebService。代碼以下,調用的仍是手機號碼歸屬地查詢,兩個參數,一個手機號碼,一個用戶Id。web

  
  
  
  
  1. <mx:WebService id="WS" wsdl="http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl"   
  2.  fault="Alert.show(event.fault.faultString), 'Error'" > 
  3.         <mx:operation name="getMobileCodeInfo" resultFormat="object"  result="GetCourse(event)"> 
  4.             <mx:request> 
  5.                 <mobileCode>{txtMobileNumber.text}</mobileCode> 
  6.                 <userID>{txtUserId.text}</userID> 
  7.             </mx:request> 
  8.         </mx:operation> 
  9. </mx:WebService> 

看看as是怎麼寫的,代碼以下ide

  
  
  
  
  1. function GetCourse(event:ResultEvent)  
  2.             {  
  3.                 var result:XML=new XML(event.result.toString());  
  4.                 if(result.Error!=null&&result.Error!="")  
  5.                 {  
  6.                     labInfo.text=result;  
  7.                 }  
  8.                 else{  
  9.                     labInfo.text="調用失敗!";  
  10.                 }  
  11.             } 

而後在某個按鈕下寫個click事件,<mx:Button x="137" y="67" label="調用WebService方法" click="showMsg();" width="141"/>對應的as代碼以下this

  
  
  
  
  1. function showMsg()  
  2.         {  
  3.              WS.getMobileCodeInfo();  
  4.         } 

看看運行效果,以下圖spa

怎麼樣很簡答吧。最後再看看如何彈出一個modal頁面。orm

  
  
  
  
  1. <mx:TitleWindow x="241" y="163" width="539" height="260" id="titleWindow"  layout="absolute" title="學生信息詳細信息" visible="false"> 
  2.              <mx:Button x="452" y="196" label="關閉" width="57" click="closeHandler();"/> 
  3.              <mx:RichTextEditor x="10" y="10" title="Title" height="180" width="499"> 
  4.              </mx:RichTextEditor> 
  5.      </mx:TitleWindow> 

as代碼以下xml

  
  
  
  
  1. import mx.managers.PopUpManager;  
  2. private function closeHandler(): void{               
  3.                   PopUpManager.removePopUp(titleWindow);     
  4.                   titleWindow.visible=false;  
  5.              }  
  6.              function showPop()  
  7.              {  
  8.                 titleWindow.visible=true;    
  9.                 PopUpManager.addPopUp(titleWindow,this,true);    
  10.              } 

運行效果以下blog

今天就寫這些,祝你們龍年愉快。事件

相關文章
相關標籤/搜索