/**************************************** Nombre de la clase: FRemoting Autor: Dano www.danonino.org Versión: 0.2 Proyecto: ¿Unknown? Licencia: GNU/GPL Fecha: 24-Febrero-2006 ****************************************/ import mx.remoting.Service; import mx.rpc.RelayResponder; import mx.rpc.FaultEvent; import mx.rpc.ResultEvent; class Danonino.FRemoting { static var MSGError = "Error in the method: "; static var MSGErrorNoGateway = "You must set the gateway"; static var MSGErrorNoService = "You must set the service"; private var objAnswer:RelayResponder; private var AMFService:Service; private var Calls:Array; public var events:Object; function FRemoting(slGateway:String, slService:String){ if( !slGateway ){ trace(MSGErrorNoGateway); } if( !slService ){ trace(MSGErrorNoService); } objAnswer = new RelayResponder(this, "onAnswer", "onError"); AMFService = new Service(slGateway, null, slService, null, objAnswer); Calls = new Array(); events = new Object(); } private function onAnswer(data):Void { var strFunction:String; strFunction = Calls[0].userFunction; strFunction = strFunction.substr(0, 1).toUpperCase()+strFunction.substr(1, strFunction.length-1); events["on"+strFunction].apply(events._parent, [data.result]); Calls.shift(); if (Calls.length>0) { callService(Calls[0].userFunction, Calls[0].userArguments); } } private function onError(fault):Void { trace(MSGError+Calls[0].userFunction); trace(fault.fault.faultstring); events.onError(fault.fault.faultstring); } public function process(userFunction:String, userArguments:Array):Void { userArguments = (userArguments == undefined) ? new Array() : userArguments; if (Calls.length == 0) { callService(userFunction, userArguments); } var objService = new Object(); objService.userFunction = userFunction; objService.userArguments = userArguments; Calls.push(objService); } private function callService(userFunction:String, userArguments:Array){ AMFService[userFunction].apply(this, userArguments); } }