Remoting with BlazeDS from plain vanilla Actionscript 3 class

Thursday, 21 August 2008 | Labels: , | |

I wanted to use BlazeDS from within my plain AS3 project (no mxml or Flex, well of course I need to use the Flex remoting and rpc classes on the client). I found a number solutions on the web, unfortunatly none of them worked. After much effort I got a example almost working but I kept getting this error on the client:

TypeError: Error #1034: Type Coercion failed: cannot convert Object@13e9921 to mx.messaging.messages.ErrorMessage.

and this error on the server:

No destination with id 'null' is registered with any service.

Fortunally Peter Farland over at the Adobe product forums gave me a (rather obscure) solution:
http://www.adobeforums.com/webx/?13@618.wIQPiTpvUo4@.59b6384e/0

I thought I'd document the full solution here in case anybody else ran into the same problem.

Environment

  1. BlazeDS, the recommended turnkey installation (my file was blazeds_turnkey_3-0-0-544.zip)
  2. Flex 3 SDK
  3. Flash Develop 3
Setup

  1. Unzip the BlazeDS zip file and start the sample DB and then Tomcat as the standard instructions say.
  2. Check the sample 3 in the "Take the test run", you should get a grid up with a load of camera data.
  3. Go to the [BlazeDS install directory]\tomcat\webapps\ROOT\ and copy the crossdomain.xml file there
  4. Now open you AS3 dev enviroment, I used Flash Develope, but Flex builder, Flash IDE or FDT will do.
  5. Create a project and copy the Main.as source file at the end of this post as the main class.
  6. Check the url in the code is correct for you
  7. Run it, you should see a load of trace. In that trace there you should see the same information as when you ran example.
My next post will be about configuring your own services and classes on the server, and maybe a more general solution...

Files
Main.as
crossdomain.xml


10 comments:

  1. Scott says:

    Hi, you've got some interesting stuff here, but none of your links are working. Can't see any of your demos or download any files. Pity.

  2. Chris Johnson says:

    I followed the original post to get here. the link is
    http://www.adobeforums.com/webx/.59b6384e

  3. Chris Johnson says:

    http://www.adobeforums.com/webx/.59b6384e

  4. Cristian says:

    Awesome! I've been looking forever for this!

    When adding your code into a Flash project, I get a bunch of errors complaining about missing AS files, e.g.:

    1172: Definition mx.rpc.events:FaultEvent could not be found.
    1172: Definition mx.rpc.events:ResultEvent could not be found.
    1172: Definition mx.messaging:ChannelSet could not be found.
    ...

    Any hints on what's needed to resolve those errors would be greatly appreciated!

  5. rje says:

    You need to include those files from the flex SDK, just search you FS for FaultEvent.as etc

  6. mouse says:

    Dude you are a godsend - I only wish I found this post 2 days ago.

    The registerClassAlias was the piece of the puzzle I was missing.

  7. Anonymous says:

    endpoint != null YEAHA !
    tnx

  8. Chris says:

    This is simply amazing, I have spent 3 days trying to get the whole Amf connection working in pure Actionscript. With this information, it now works great, I was stuck on 'send failed' forever.

    So is Adobe going to fix this internally ever, I see the bug is closed for it, I found that first and it led finally to your post.

    It caused me to about go insane, so would think they could save other people a lot of wasted time at least pointing to this information somehow, if not making this stuff get initialized internally automatically.


    Thanks,
    Chris

  9. Erich Cervantez says:

    I've run into the same situation and I'm racking my brain trying to figure out what the issue might be. In my case, I have a larger parent application loading a sub-application SWF. Both are capable of making service calls on their own, but once I load one inside the other, the "No destination with id 'null' is registered with any service." exception is thrown.

    The link posted in your article seems to be no longer valid/relevant. Anyway to recap whatever the solution was?

  10. bL4Ck84 says:

    simply register the RemotingMessage class when initializing the inner module.

    example:

    import mx.messaging.messages.RemotingMessage;

    private function init():void {
    registerClassAlias("flex.messaging.messages.RemotingMessage", RemotingMessage);
    }