- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
- <mx:Script>
- <![CDATA[
- import mx.rpc.events.FaultEvent;
- import mx.rpc.events.ResultEvent;
- private function onReSet(evt:Event):void{
- username.text="";
- password.text="";
- username.setFocus();
- }
- public function onSubMit(evt:Event):void{
- if(username.text.length<4||username.text.length>12){
- username.setFocus();
- return;
- }
- if(password.text.length<4||password.text.length>12){
- password.setFocus();
- return;
- }
- //Alert.show("usernmae="+username.text,"提示");
- //連接數據庫服得用戶信息
- login.send();
- }
- private function login_success(evt:ResultEvent):void{
- conShow.text+=login.lastResult.toString();
- }
- private function login_fault(evt:FaultEvent):void{
- conShow.text+=evt.fault.toString();
- }
- ]]>
- </mx:Script>
- <mx:Style>
- .errorTip{
- fontSize:12px;
- }
- </mx:Style>
- <mx:StringValidator id="reqValid" required="true" source="{username}" property="text" minLength="4" maxLength="12" tooLongError="輸入大長了,不要超過12個字"
- tooShortError="輸入太短了,不能少於4個字" />
- <mx:StringValidator id="reqValid2" required="true" source="{password}" property="text" minLength="4" maxLength="12" tooLongError="輸入大長了,不要超過12個字"
- tooShortError="輸入太短了,不能少於4個字" />
- <mx:HTTPService id="login" url="http://localhost/myphp/flex4/src/login.php" useProxy="false" showBusyCursor="true"
- resultFormat="text" method="POST" result="login_success(event)" fault="login_fault(event)">
- <mx:request>
- <username>{username.text}</username>
- <password>{password.text}</password>
- </mx:request>
- </mx:HTTPService>
- <mx:Panel x="10" y="10" width="369" height="273" layout="absolute" id="loginPanel" title="登錄" fontSize="14" fontWeight="normal">
- <mx:Form x="51" y="10" width="276" height="196" label="訪問登錄" id="form1" defaultButton="{submit}">
- <mx:FormHeading label="歡迎訪問登錄"/>
- <mx:FormItem label="用戶名" required="true" fontSize="12">
- <mx:TextInput id="username" maxChars="20"/>
- </mx:FormItem>
- <mx:FormItem label="密碼" fontSize="12">
- <mx:TextInput id="password" maxChars="20"/>
- </mx:FormItem>
- <mx:FormItem width="200" fontFamily="Arial" fontSize="12" direction="horizontal">
- <mx:Button label="提交" id="submit" click="onSubMit(event);"/>
- <mx:Button label="重寫" id="reset" click="onReSet(event);"/>
- </mx:FormItem>
- </mx:Form>
- </mx:Panel>
- <mx:TextArea x="532" y="10" id="conShow" width="210" height="77" wordWrap="true"/>
- </mx:Application>
返回數據的格式resultFormat 有幾種類型,object、array、xml、flashvars、text和e4x,默認的設置爲object。
RESULT_FORMAT_ARRAY : String = "array"
[] 結果格式“array”與“object”相似,但是其返回的值始終爲數組;這樣,如果從結果格式“object”返回的結果尚不是數組,則將把該項目添加爲一個新數組的第一個項目。
RESULT_FORMAT_E4X : String = "e4x"
[] 結果格式“e4x”指定返回的值是一個 XML 實例,此實例可以使用 ECMAScript for XML (E4X) 表達式訪問。
RESULT_FORMAT_FLASHVARS : String = "flashvars"
[] 結果格式“flashvars”指定返回的值是包含由 & 符號分隔的名稱=值 對的文本,該文本被分析爲 ActionScript 對象。
RESULT_FORMAT_OBJECT : String = "object"
[] 結果格式“object”指定返回的值是 XML,但按照 ActionScript 對象樹分析。
RESULT_FORMAT_TEXT : String = "text"
[] 結果格式“text”指定 結果文本應爲未經處理的字符串。
RESULT_FORMAT_XML : String = "xml"
[] 結果格式“xml”指定結果應作爲指向父 flash.xml.XMLDocument 的第一個子項的 flash.xml.XMLNode 實例返回。
================================================
在 MXML 文件中使用 <mx:HTTPService> 標籤代表 HTTPService 對象。當調用 HTTPService 對象的 send() 方法時,將發出對指定 URL 的 HTTP 請求,並且返回 HTTP 響應。可以選擇向指定 URL 傳遞參數。如果沒有使用基於服務器的代理服務,則只能使用 HTTP GET 或 POST 方法。如果將 useProxy 屬性設置爲 true 並使用基於服務器的代理服務,則還可以使用 HTTP HEAD、OPTIONS、TRACE 和 DELETE 方法。