P
ROTOTYPE
I'm Not Only The Prototype, I'm Also A Member.
home
▪
stats
▪
search
▪
linkback
▪
about
▪
FAQ
| user: guest,
login
,
register
Classes
:
Remoting method serializer :CF:.Net:Java: [AS1] - updated
author:
mga
[+]
,
Submitted: 11.11.03 2p
• Last Edit: 12.12.06 9a
/* * Class Connector. * Version: 1.1.0 * Desc: Serializes de-serializes Flash Remoting (CFM,.Net,Java) methods. * Author: Mauricio Giraldo Arteaga http://atari.uniandes.edu.co/mga/ * * v.1.1.0 The connector now also returns an onmethodnameStatus event with the error. * */ Connector = function (gateway) { this.gateway = gateway; this.init(); } Connector.prototype.atrapa = function (obj) { this.onResult = function (result) { if (result) { trace("results received"); obj["on" + obj.pidiendo](result); } else { trace("error"); } } this.onStatus = function (error) { trace("error: " + error.details); obj["on" + obj.pidiendo + "Status"](error); } }; Connector.prototype.init = function () { // connect to the Flash Remoting service provider if (this.isGatewayOpen == null) { // do this code only once this.isGatewayOpen = true; // Make the Gateway connection NetServices.setDefaultGatewayUrl(this.gateway); this.conn = NetServices.createGatewayConnection(); trace("connected!"); } }; Connector.prototype.ejecutar = function (servicename,methodname,params) { trace("component: " + servicename + "\nexecuting: " + methodname + "\nparam: " + params); this.servicio = this.conn.getService(servicename,new this.atrapa(this)); this.pidiendo = methodname; this.servicio[methodname](params); };
usage
This code is pretty generic for connecting via Flash Remoting MX to multiple components with multiple methods. It generates an onmethodname() event - i.e. ongetNews(). For multiple parameters, it is currently implemented that you must provide an array, object, char-separated string or other in params and then split or parse in the web service. Give it a try and let me know if you got any issues/questions. Mauricio Sample: [code] #include "NetServices.as" #include "Connector.as" function init () { var gateway = "http://www.mysite.com/flashservices/gateway"; var conn = new Connector(gateway); // parameters must be formatted as expected by the method to be used var myparams = ["bob","john","paul","mary"]; conn.ejecutar("path.cfcname","methodname",myparams); // an event will be generated when information is received // the event will be named after the methodname prefixing it with "on" conn.onmethodname = function (results) { // do something with the results } } init (); [/code]
Add Comment
[+]
›opyleft 2001-2010. Layer51 is: Jaime Prado.
@