How do you Extend RemoteObject?

Someone saw this old thread from the FlexCoders list and e-mailed me one solution. This was the question:

I'd like to have a custom remoteobject for specific error handling and logging. However, if I try to extend remoteobject:

public dynamic class CustomRemoteObject extends RemoteObject { ... }

It is completely unusable in an mxml file. If I try to declare any inside of it, I get a "could not resolve to a component implemenation":


<components:CustomRemoteObject>
<mx:method ...> <!-- compiler error -->
</components:CustomRemoteObject>

I know that is special-cased by the compiler because it doesn't have a component implementation. Is there a way to use custom remote objects in mxml with the mx:method tag? If not, is there a way to use custom remote objects in mxml and have callbacks at the method-level? Is remoteobject not supposed to be extended this way?

My answer at the time was to try this:


<components:CustomRemoteObject>
<components:method ...>
</components:CustomRemoteObject>

However, I doubt that works. As the original poster had stated, the method tag appears to be a compiler kludge. You can't extend RemoteObject and specify the methods in the same way. The method tags are not specified as an array and method is not a property on the RemoteObject class. I bet the compiler turns all the method tags into an operations array, although I haven't checked actual generated code.

The real solution to generating is to review the generated code from the Flex Compiler in a template that uses RemoteObject w/ multiple method tags and then figure out what it does; then replicate that approach in your own ActionSript.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Simeon Bateman's Gravatar One of the things to look into here is that there are actually 2 RemoteObject classes in the framework. One in mx.rpc.remoting and one in mx.rpc.remoting.mxml. The .mxml version extends the other.

So extension of remoteobject can happen. The trick is probably to take a look the source of the .mxml.RemoteObject and see what it does to extend RemoteObject and then do the same thing.
# Posted By Simeon Bateman | 7/27/10 2:29 PM
All Content Copyright 2005, 2006, 2007, 2008, 2009 Jeffry Houser. May not be reused without permission
BlogCFC was created by Raymond Camden. This blog is running version 5.9.2.002.