- <?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 方法。