[swx] SWX Object exists, but call isn't executed

Nederflash (Folkert Hielema) info at nederflash.nl
Mon Apr 14 08:56:13 PDT 2008


You should really use the SWX actionscript api and with that you best 
use a SWXService singleton class.
Wherever you need swx you just call the SWXService.getInstance();

Your singleton class would only hold the information you want at hand 
(see below), any dynamic stuff you send through the call like this basic 
usage:

var service = SWXService.getInstance();
var data = {};
data['service'] = "Twitter";
data['type'] = "userTimeLine";
data['command'] = this;
data['args'] = [ user,pass,friendID,20,null ]
service.swxCall(data);

where data['command'] takes care of the reference to the place you have 
this script for onResult and onFault handlers.
That way your inplace error and resultHandlers which will automatically 
be called from your SWXService singleton class. just put your onResult 
and onFault at the place you do the swxCall.

Within the SWXService singleton class needs 4 methods basically which 
are getInstance(),swxCall(), onResult and onFault (maybe onTimeout also)

the SWXService class has a few vars and sets a few defaults so class may 
look like:
//////////file SWXService.as//////////
import org.osflash.SWX;
class SWXService {
   static var instance:SWXService=null;
   var swx:SWX;//instance of the real SWX
   private var gatewayURL:String = "http://mygateway.com/php/swx.php";
   private var debug:Boolean = true;//false for production
   var methodParams:Object;
   private var defaultService:String = "SomeService";
   private var defaultEncoding:String = "GET";
   //commandTarget, reference to callback onResult or onFault
   private var commandTarget;//untyped path back to where call was from
   public function SWXService()
   {
     swx = new SWX  ;
     swx.gateway = this.gatewayURL;
     swx.encoding = this.defaultEncoding;//overwrite when needed
     swx.debug = this.debug;
   }
   public static  function getInstance()
   {
     instance = (instance != null) ? instance : new SWXService();
     return instance;
   }
   public function onResult(eventObj)
   {
     commandTarget.onResult(eventObj.result);
   }
   public function onTimeOut(eventObj)
   {
     eventObj.description="WARNING SWXService timedOut try again later";
     commandTarget.onFault(eventObj);
   }
   public function swxCall(data)
   {
     //set up method parameters as there dynamic
     swx.encoding = (data.encoding != undefined) ? data.encoding : 
defaultEncoding;
     commandTarget = data.command;
     var service:String = (data.service!=undefined) ? data.service : 
defaultService;
     methodParams={
       serviceClass:service,
       method:data.type,
       args:data.args,
       result:[this,onResult],
       timeout:[this,onTimeOut]
     };
     swx.call(methodParams);
   }
}
//////////end file SWXService.as//////////

Something in the lines of this would help you greatly to reduce root 
based calls like you do in your examples.

hope that helps,

Folkert






More information about the swx mailing list