AARON SMITH’S CODE ENDEAVOR

Guttershark Service Abstraction Updates

I’m working on revamping the service abstractions in Guttershark. I’ll be completely removing the ServiceManager in favor of using a class directly (like HTTPCall, SoapService, etc). I’ve got the http stuff done, and need to update soap and remoting. The http code is the most drastically changed. The soap and remoting code won’t change too much.

I’ve got a couple examples in the repo for the new HTTPCall class. But in short, here’s how you use it:

package
{
	import gs.core.DocumentController;
	import gs.service.http.HTTPCall;
	import gs.service.http.HTTPCallResponseFormat;
	import gs.service.http.HTTPCallResult;
 
	public class Main extends DocumentController
	{
 
		private var hc:HTTPCall;
 
		public function Main()
		{
			super();
		}
 
		override protected function setupComplete():void
		{
			hc=new HTTPCall("http://www.google.com/");
			hc.responseFormat=HTTPCallResponseFormat.TEXT;
			hc.setCallbacks(onResult);
			hc.send();
		}
 
		protected function onResult(r:HTTPCallResult):void
		{
			trace(r.text);
		}
	}
}

And if you look through the docs, it supports a bunch of other stuff - retries, timeouts, more response formats than URLLoaderResponseFormat, and you can optionally set callbacks instead of using .addEventListener. Which is a nice alternative that allows you to setup the handlers you need in one line of code. Of course you can still opt in to using .addEventListener.

  

5 Comments so far

  1. penny March 9th, 2010 3:46 am

    Hi,

    is it possible to cancel a call. Lets say I call remote method to get results from querry entered by user. Meanwhile the results come from server user enters other querry and calls for search again. I would like to cancel previous call which havent returned anything yet. Should I setCallbacks to null and call method again or it can be done in some other way?

  2. admin March 9th, 2010 1:43 pm

    Yeah that’s a good point. I’ll get that in. Right now you can access the loader object and close it.

  3. penny March 11th, 2010 3:33 am

    I meant the RemotingCall, not the ServiceCall. Maby dispose method could do that before nulling rs?

  4. penny May 4th, 2010 4:02 am

    Any news on that?

    This call:

    _remotingCall.close();
    _remotingCall.setCallbacks( { onResult: null, onFault: null, onTimeout: null, onRetry: null, onFirstCall: null, onConnectFailed: null, onBadVersion: null, onClosed: null, onProhibited: null, onSecurityError: null, onClose: null } );
    _remotingCall = null;

    causes
    TypeError: Error #1009: Nie można uzyskać dostępu do właściwości lub metody dla odniesienia do obiektu null.
    at gs.remoting::RemotingCallResultHandler/process()
    at gs.remoting::RemotingCall/_result()

  5. u10int May 5th, 2010 9:54 am

    I’m getting the same error as @penny when trying to use the new remoting classes in my application, but not necessarily in the same instance. Here’s my code block:

    var rc:RemotingCall = Model.get(”AppModel”).getRemotingCallById(”amfphp”, “PlayerLogger.ping”);
    rc.setCallbacks({onResult:onResult, onFault:onFault, onConnectFail:onFail, onClosed:onClose});
    rc.send(sysid, ca.libraryName, ca.assetType, ca.source, MathUtils.round(MathUtils.byte2Megabyte(System.totalMemory), 3));

    …which results in this error:

    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at gs.remoting::RemotingCallResultHandler/process()[/Users/nshipes/Library/Application Support/Adobe/Flash CS4/en/Configuration/Classes_AS3/gs/remoting/RemotingCallResultHandler.as:25]
    at gs.remoting::RemotingCall/_result()[/Users/nshipes/Library/Application Support/Adobe/Flash CS4/en/Configuration/Classes_AS3/gs/remoting/RemotingCall.as:488]

    However, I tested using the remoting2 example, but replaced remoting services in the model with mine and modified the library/id references in Main.as and it worked fine. I’m not really seeing what the difference between the two is that would be causing the error in my code.

    Any ideas? Thanks!
    }

Leave a reply