/**//* 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); }