php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>flex login</title>
</head>
<body>
<?php
$return="";
if(isset($_POST[username]) && isset($_POST[userpwd])){
if ("User"==$_POST[username] && "123456"==$_POST[userpwd])
$return="ok";
else
$return="error";
}
$xml_return = '<users>';
$xml_return.= '<a>'.$return.'</a>';
$xml_return.= '</users>';
echo $xml_return;
?>
</body>
</html>
Flex:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
horizontalAlign="center"
verticalAlign="middle">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
private function goLogin():void
{
login.send();
}
private function resultHandler(event:ResultEvent):void
{
Alert.show(event.result.html.body.users.a.toString());
}
]]>
</mx:Script>
<mx:HTTPService id="login"
method="POST"
showBusyCursor="true"
url="http://localhost/php/login.php"
result="resultHandler(event)">
<mx:request>
<username>
{username.text}
</username>
<userpwd>
{userpwd.text}
</userpwd>
</mx:request>
</mx:HTTPService>
<mx:Panel width="310"
height="265"
layout="absolute"
title="登录"
fontSize="12"
fontWeight="normal"
x="296"
y="153">
<mx:TextInput x="93"
y="51"
id="username"
fontSize="12"/>
<mx:TextInput x="92"
y="95"
id="userpwd"
fontSize="12"
displayAsPassword="true"/>
<mx:Button x="73"
y="154"
label="登录"
id="btn1"
click="goLogin()"
fontWeight="normal"
fontSize="12"/>
<mx:Label x="32"
y="53"
text="用户名:"
fontSize="12"/>
<mx:Label x="43"
y="97"
text="密码:"
fontSize="12"/>
<mx:Button x="154"
y="154"
label="注册"
fontSize="12"
fontWeight="normal"
id="btn2"/>
<mx:Label x="10"
y="10"
text="测试用 用户名 User 密码 123456"
fontSize="12"
width="243"/>
</mx:Panel>
</mx:Application>
重要的把返回 结果看作xml,
<html>
<body>
<users>
<a>
</a>
</users>
</body>
</html>