Archive for May, 2007

Handling Awkward Remote Service Logic

Every so often with Remoting I experience awkward situations where I need to return either true or some sort of error other than false. An example awkward sitatution is a registration method.

The method requires an email and password. There are 4 “falt” situations that come to mind right away. (1) Empty email address. (2) Empty password. (3) Email is not valid format. (4) The email is not unique. The “awkward” part is that even when returning anything other than true, the result still comes back to the onResult method. I’ve seen other people’s logic return an object with some special keys set. For EX: {error:true, message:’some message’}. But that is still awkward because they were testing for that object in every onResult method. See what the problem is? There needs to be an error state in Flash but the onResult method is always called.

A solution in RubyAMF is the new FaultObject helper. In services/rubyamf/helpers/fault_object. Returning this object from a service method call results in a behind the scenes switcheroo that returns a valid Fault object to the player. It works with AMF0 / AMF3 / RemoteObject.

Here is a simple RubyAMF example:

require RUBYAMF_HELPERS + 'fault_object'
class MyService
 def register(email, password)
  if(!email)
   return FaultObject.new("EMAIL_EMPTY", "Email can not be empty.")
  end
 end
end

Now let’s assume MyService#register is attempted from Flash with an empty email. The result is a correct mapping to the onFault handler with code / faultCode and description / faultString set. Simple!

This new feature will be in the next release (0.9.2). It’s in SVN right now.

What about you AMFPHP folks? If you use SSR:Super Simple Remoting the package has a built in forward to onFault when the keys “faultCode” and “faultString” are present in whatever the result is. For ex, if you return this:

return $o = array( "faultString" => "some Message", "faultCode" => "someCode" );

The result get’s forwarded to your onFault handler instead. Sweet!

New AMFPHP Website

The new site is amf-php.org.

SSR: Super Simple Remoting

To go along with RubyAMF. I am releasing this pretty cool remoting package for AS3 I wrote over the last couple days. Remoting is as you guessed it – Super Simple with this package. It uses callbacks for each service call’s onResult and onFault. It allows for timeout’s and maxAttempts to be specified as well.

Example:

package
{

	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import org.rubyamf.remoting.ssr.RemotingService;
	import org.rubyamf.remoting.ssr.ResultEvent;
	import org.rubyamf.remoting.ssr.FaultEvent;

	class MyServiceTest extends Sprite
	{

		private var service:RemotingService;

		private function MyServiceTest()
		{
			service = new RemotingService('http://localhost:8024/gateway.rb','test.Test', [0/3]);
			service.addEventListener(FaultEvent.CONNECTION_ERROR, onConnectionError);
			myButton.addEventListener(MouseEvent.CLICK, testService);
		}

		function onConnectionError(fe:FaultEvent):void
		{
			trace("Connection Error: " + fe.fault);
		}

		function onResult(re:ResultEvent):void
		{
			trace(re.result);
		}

		function onFault(fe:FaultEvent):void
		{
			trace(fe.fault.faultString);
		}

		function testService(e:Event):void
		{
			//perform the service call
			service.helloWorld(['Hello World!'], onResult, onFault, {timeout:3000, maxAttempts:2});
		}
	}
}

Download SSR | SSR on OSFlash

PNGPong: Cross-browser solution for displaying transparent PNG’s

PNGPong is a really good solution for cross browser transparent PNG support. It’s super easy to use. One line of javascript will get you alpha support on all browsers. If the user-agent is IE, pngpong uses it’s own swf to load and display the image. There are more options to do roll overs, call javascript methods, etc. Definitely check it out.

Instiki Crashing

The RubyAMF wiki has been experiencing more volume than usual and instiki can’t seem to handle it. I’ll be working to fix this over the next couple days. I’d be willing to bet the problem is relying on WEBrick. It was fine when I was only getting a few hits but now it seems I need to get Instiki running on LightTPD.

Hi There!

I’ve decided to start blogging about RubyAMF and where it’s headed. It’s not going to be a daily thing. Just experiences I’ve had using it and integrating it with Apollo / Flex / Flash and other cool things.

Later – Aaron.