<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" layout="absolute" fontSize="14" fontFamily="arial">
<mx:Script>
<![CDATA[
import mx.controls.Alert; //引入Alert完整组件类
private function check():void{
if(username.text==""){
Alert.okLabel="确定"; //修改OK按钮上的文字
//调用Alert.show()弹出对话框,对话框上有确定和取消按钮
Alert.show("用户名不能为空","警告",Alert.OK);
}
if(username.text!=""&&pwd.text==""){
Alert.okLabel="确定"; //修改OK按钮上的文字
//调用Alert.show()弹出对话框,对话框上有确定和取消按钮
Alert.show("密码不能为空","警告1",Alert.OK);
}
if(username.text!=""&&pwd.text!=""){
userRequest.send();
viewstack1.selectedChild=View2;
}
}
]]>
</mx:Script>
<mx:Script>
<![CDATA[
import mx.controls.Alert; //引入Alert完整组件类
private function resetvalue():void{
username.text="";
pwd.text="";
}
]]>
</mx:Script>
<mx:HTTPService id="userRequest" url="checklogin.php" useProxy="false" method="POST">
<mx:request xmlns="">
<username>{username.text}</username><pwd>{pwd.text}</pwd>
</mx:request>
</mx:HTTPService>
<mx:ViewStack x="226" y="49" id="viewstack1" width="619" height="700">
<mx:Canvas id="View1" width="100%" height="100%">
<mx:Form x="151" y="222" width="444">
<mx:Panel x="153" y="201" width="397" height="320" layout="absolute">
<mx:Label x="90" y="70" text="用户名" width="49"/>
<mx:Label x="90" y="117" text="密码" width="49"/>
<mx:TextInput id="username" x="172" y="70" width="118"/>
<mx:TextInput id="pwd" x="172" y="117" width="118" displayAsPassword="true"/>
<mx:Button x="116" y="182" label="登录" click="check()"/>
<mx:Button x="212" y="182" label="重填" click="resetvalue()" />
</mx:Panel>
</mx:Form>
</mx:Canvas>
<mx:Canvas id="View2" width="100%" height="100%" color="#000000">
<mx:Label id="greetword" text="{userRequest.lastResult.users.user.result}" fontSize="16" color="#FF0000" x="268.5" y="291">
</mx:Label>
<mx:Label id="email" text="{userRequest.lastResult.users.user.email}" x="268.5" y="345" width="293" height="19"/>
</mx:Canvas>
</mx:ViewStack>
</mx:Application>
checklogin.php
<?php
header("content-type:text/html;charset=utf-8");
include "conn.php";
$sql="select * from userinfo where username='".$_REQUEST["username"]."' and pwd='".$_REQUEST["pwd"]."'";
$result=mysql_query($sql);
$xml_return = "<users>";
if ($user = mysql_fetch_array($result)){
$xml_return .="<user><result>登录成功</result><userid>".$user['id']."</userid><username>".$user['username']."</username><email>您的email:".$user['email']."</email></user> ";
}
else{
$xml_return .="<user><result>用户密码错误!</result><userid></userid><username></username><sex></sex></user> ";
}
$xml_return.= "</users>";
echo $xml_return;
?>