先看看Flex如何調用WebService。代碼以下,調用的仍是手機號碼歸屬地查詢,兩個參數,一個手機號碼,一個用戶Id。web
- <mx:WebService id="WS" wsdl="http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl"
- fault="Alert.show(event.fault.faultString), 'Error'" >
- <mx:operation name="getMobileCodeInfo" resultFormat="object" result="GetCourse(event)">
- <mx:request>
- <mobileCode>{txtMobileNumber.text}</mobileCode>
- <userID>{txtUserId.text}</userID>
- </mx:request>
- </mx:operation>
- </mx:WebService>
看看as是怎麼寫的,代碼以下ide
- function GetCourse(event:ResultEvent)
- {
- var result:XML=new XML(event.result.toString());
- if(result.Error!=null&&result.Error!="")
- {
- labInfo.text=result;
- }
- else{
- labInfo.text="調用失敗!";
- }
- }
而後在某個按鈕下寫個click事件,<mx:Button x="137" y="67" label="調用WebService方法" click="showMsg();" width="141"/>對應的as代碼以下this
- function showMsg()
- {
- WS.getMobileCodeInfo();
- }
看看運行效果,以下圖spa
怎麼樣很簡答吧。最後再看看如何彈出一個modal頁面。orm
- <mx:TitleWindow x="241" y="163" width="539" height="260" id="titleWindow" layout="absolute" title="學生信息詳細信息" visible="false">
- <mx:Button x="452" y="196" label="關閉" width="57" click="closeHandler();"/>
- <mx:RichTextEditor x="10" y="10" title="Title" height="180" width="499">
- </mx:RichTextEditor>
- </mx:TitleWindow>
as代碼以下xml
- import mx.managers.PopUpManager;
- private function closeHandler(): void{
- PopUpManager.removePopUp(titleWindow);
- titleWindow.visible=false;
- }
- function showPop()
- {
- titleWindow.visible=true;
- PopUpManager.addPopUp(titleWindow,this,true);
- }
運行效果以下blog
今天就寫這些,祝你們龍年愉快。事件