Bumpslide AS3 RPC Classes
I have been refactoring my service loading application code recently, and I am moving away from my URLLoaderQueue in favor of classes that represent individual requests. After doing a few Flex projects, I really like the IResponder interface, and when using that in conjunction with the Command pattern, it just makes sense to have a URL request implementation that can use this responder interface. Much of this code is inspired by code in the Flex framework, but note that there are no Flex dependencies here. This code is designed for those that like the idea of IResponder and the Flex service classes but don’t want to get bogged down in the Flex.
see com.bumpslide.net.*
(ignore URLLoaderQueue and URLLoadRequest which are deprecated)
At the simplest level, when you need to load a URL, use HTTPRequest instead of URLLoader. This will give you error handling, timeouts, and retries on failure. It also works hand-in-hand with my version of the IResponder interface to allow for easy callbacks on success and failure.
To go just a bit deeper, you will notice that HTTPRequest implements IRPCRequest which is a simple declaration of what is essential to represent a service call. Extended from HTTPRequest are JSONRequest and XMLRequest which take care of turning the loaded data into a meaningful result object.
For a basic example of how this fits in with the Command pattern, take a look at com.bumpslide.command.ServiceCall.as. This class can be used as a template when creating your own commands.
If you need a queue, you can use the CommandQueue here, or you can implement your own with the ActionQueue class. This would be useful, for instance, if you are creating an AS3 service API or some other set of service methods all in one class (which is what I did in my app template). I should probably just create a request queue that can formally replace the URLLoaderQueue. If anyone wants to jump on that, the LoaderQueue and CommandQueue are both classes that use the prioritizable and “multi-threaded” ActionQueue to do the queue management. Porting one of those to support IRPCRequest should be quite easy. Ben McMaster, I’m talking to you, buddy. :)

November 19th, 2008 at 1:22 pm
note, this code is all still quite fresh, and it not yet included in any of the zip builds. Grab the latest from SVN if you want to play with it.
http://bumpslide.googlecode.com/svn/trunk/as3/