之前自己写了REMOTING类,但看了 bico_wing (flashcom.com.cn上的名字) 的方法觉得确实比我的简单很多,所以拿来跟大家分享一下:
先建立Remoting.as文件:

/**//*
Remoting类
负责FLASH与数据库交互
*/
package net.smilecn.net...{
import flash.net.Responder;
import flash.net.NetConnection;

public class Remoting extends NetConnection ...{
/**//*
构造
@param gatewayURL remoting网关地址
@param amfType 使用AMF3或AMF0
*/
public function Remoting(gatewayURL:String,amfType:uint) ...{
super();
this.objectEncoding=amfType;
this.connect(gatewayURL);
}
//##########################################################################
//
//方法
//
//##########################################################################
/**//*
* 远程返回函数
* @param remoteMethod:远程类.方法名param远程方法所需要的参数onResultFun:返回数据所调用的方法句柄.onFaultFun同理.
*
*/
public function respond(remoteMethod:String,onResultFun:*,onFaultFun:*,... param):void ...{
var parameters:Array=param;
if (param.length > 0) ...{
parameters.unshift(remoteMethod,new Responder(onResultFun,onFaultFun));
this.call.apply(this,parameters);
} else ...{
this.call(remoteMethod,new Responder(onResultFun,onFaultFun));
}
}
}
}然后在任何地方可以调用它:
var remote:Remoting;
remote=new Remoting("http://localhost/remotinggame/gateway.aspx",0);
remote.respond(remoting方法名,onRuslt,onFault,参数1,参数2....);

function onRuslt(re:*):void...{
trace(" onRuslt:"+re);
}

function onFault(fe:*):void...{
trace(" onFault:"+fe.code);
}
本文介绍了一种简化版的Flash Remoting实现方法,通过自定义Remoting类来简化Flash与服务器之间的通信流程。该方法利用NetConnection进行数据交互,并通过Responder处理响应。
5786

被折叠的 条评论
为什么被折叠?



