17 May 2007

Extensible ServiceLoader

As part of the solution to the problem below, I've created a new ServiceLoader class that can be used for any remoting applications. Here's the class:


import mx.remoting.*;
import mx.rpc.*;

class com.utils.ServiceLoader {

private var __servicePath:String;

function ServiceLoader(servicePath:String){
__servicePath = servicePath;
}

private function __openService(remoteName:String):Service {
trace(remoteName);
return new Service(__servicePath, null, remoteName);
}


public function callService(serviceName:String, methodName:String, scope:Object, success:String, error:String, args:Array):Void{
var pc:PendingCall = __openService(serviceName)[methodName].apply(this,args);
pc.responder = new RelayResponder(scope, success, error);
}
}

Here's an example call of this class:

var service:Object = new ServiceLoader("http://localhost:8300/flashservices/gateway/");

service.callService("serviceName", "serviceMethodName", this, "successHandler", "errorHandler" [,optional argument Array]);


So the ServiceLoader class calls whatever service you need and returns the result to handlers in a specified scope ("this" i.e. the calling class, in above the example).

1 comment:

Dan said...

I've discovered a resolution to this problem here:

Resolution to the Flash 3 minute load