时间:2021-07-01 10:21:17 帮助过:30人阅读
代码如下:
import mx.controls.Alert;
import mx.rpc.remoting.mxml.RemoteObject;
import mx.rpc.events.*;
public var login_remoteObj:RemoteObject = null;
public function initLoginRemoteObject():void
{//初始化RemoteObject
this.login_remoteObj = new RemoteObject();
this.login_remoteObj.source = "Login";
this.login_remoteObj.destination = "amfphp";
this.login_remoteObj.showBusyCursor = true;
this.login_remoteObj.endpoint = "http://localhost/MyTest/amfphp/gateway.php";
this.login_remoteObj.doLogin.addEventListener("result", loginHandler);
this.login_remoteObj.doLogin.addEventListener("fault", faultHandler);
}
public function doLogin():void
{//登陆操作,向服务器提交数据
var name:String = this.txtName.text;
var pwd:String = this.txtPassword.text;
var data:Array = new Array();
data.push(name);
data.push(pwd);
this.login_remoteObj.getOperation("doLogin").send(data);
}
public function loginHandler(event: ResultEvent):void
{//处理服务器返回的结果
var result:Array = event.result as Array;
var flag:String = result[0];
if (flag == "0") {
Alert.show("登陆失败: " + result[1]);
} else if (flag == "1") {
Alert.show("登陆成功: " + result[1]);
} else if (flag == "-1") {
Alert.show("异常: " + result[1]);
}
}
public function faultHandler(event: FaultEvent):void
{//出错处理
Alert.show("sorry,出错了!!!");
}
}
代码如下:
http://localhost/MyTest/amfphp/gateway.php
代码如下:
class Login
{
public function doLogin($data)
{
$result = array();
try {
$name = array_shift($data);
$pwd = array_shift($data);
if ($name == "phinecos" && $pwd == "123") {
$result[] = "1";
$result[] = "you are valid user!";
} else {
$result[] = "0";
$result[] = "login failed";
}
} catch (Exception $ex) {
$result[] = "-1";
$result[] = $ex->getMessage();
}
return $result;
}
}
?>
代码如下:
$servicesPath = "../BusinessLogic/";
以上就介绍了 AMFPHP php远程调用RPC, Remote Procedure Call工具 快速入门教程,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。