Doing some re-factoring today in a Flex 1.5 project, and realized a lot of our Commands & Delegates we’re implementing the Cairngorm’s Responder interface, but using vanilla (plain) Objects for the onResult and onFault functions. While that is the correct implementation of the interface, if you are using Remoting in Flex (RemoteObject, or even WebService / HTTPService), then that is technically correct, but not entirely accurate. Result events actually get mx.rpc.ResultEvent instances, and fault events get mx.rpc.FaultEvent.
function onResult ( event : Object ) function onFault ( event : Object )
…is ok, the correct way is to do:
function onResult ( event : mx.rpc.ResultEvent ) function onFault ( fault : mx.rpc.FaultEvent )
Doing this, however, will break the interface’s contract. What I did is fix the interface. Good news is, if your existing code base already uses event : Object, that’s ok; ResultEvent & FaultEvent extend Object, so compiler wise, you are technically fulfilling the interface’s contract.
This is corrected in Cairngorm 2, although, the example casting in the comments is incorrect. While casting actually works in ActionScript 3, because of some frikin’ geniuses at Netscape (sarcastic) decided to keep backwards compatibility in a language spec (ECMA Script), you should really cast via “something as Class” vs. “Class ( something )” since the most commonly used client / server datatype, Array, cannot be used this way.
Benefits of doing this in Flex 1.5 is using strict datatyping for ResultEvent and FaultEvent properties, and easier to port to Flex 2. If you don’t cast in Flex 2, it’ll cost you speed as the interpreter will have to downcast the result to ensure it’s truly an Object and do dynamic lookups of properties.