4 Replies Latest reply on May 20, 2011 5:14 AM by Rohit . Kumar

    Conversion between ASObject and custom Java object

    Franekek12

      I have Java Enterprice Application with BlazeDS installed there and Flash client (created in pure Flash -not Flex). Now I want to send my custom Java object over the wire.

       

      On The java side i have method:

      //////////////////////

      public void echo1(Dupa dupa){

           System.out.println("--");

           System.out.println(dupa.dup);

           System.out.println("--");

      }

      //////////////////////

      On the Flash side:

      ////////////////////////

      var myDupa:Dupa = new Dupa();

      myDupa.dup = "www";

      var rooms:Object = remoteObject.echo1(myDupa);

      ////////////////////////

      Where object's 'Dupa' definition is:

      Java:

      /////////////////////////

      package test;

       

      public class Dupa {

       

           public String dup;

       

      }

      //////////////////////////

      Flash:

      /////////////////////////

      package test {

      [Bindable]

      [RemoteClass(alias="test.Dupa")]

      public class Dupa {

       

            public var dup:String;

       

      }

      }

      /////////////////////////

       

      And I always receives error:

      //////////////////////////

      [FaultEvent fault=[RPC Fault faultString="Cannot invoke method 'echo1'." faultCode="Server.ResourceUnavailable" faultDetail="The expected argument types are (test.Dupa) but the supplied types were (flex.messaging.io.amf.ASObject) and converted to (null)."] messageId="2EEB750E-240E-9AE3-9AE4-284E56C81B89" type="fault" bubbles=false cancelable=true eventPhase=2]

      //////////////////////////

       

      When i change me Java method signature to:

       

      public String echo2(flex.messaging.io.amf.ASObject test){...}

       

      Everything work fine. But it this situation I have ASObject which i have to convert to test.Dupa.

       

       

      The question is:

      How can i force Flash to convert sent content to my custom object (test.Dupa)?

      If its not possible, how can I convert ASObject object to test.Dupa (or whatever I want).

       

      Thx fo replies.

       

       

       

       

        • 1. Re: Conversion between ASObject and custom Java object
          Rohit . Kumar Adobe Employee

          Looks like RemoteClass tag did not have any effect. Can you try the following: Within the Dupa AS class, decare a constructor and explictly call the flash.net.registerClassAlias("test.Dupa", test.Dupa) in it.

           

          Rohit

          1 person found this helpful
          • 2. Re: Conversion between ASObject and custom Java object
            Franekek12 Level 1

            It helped! Thank You very much.

            But there is another question (or two):

             

                 Why the "RemoteClass" metadata is not recognized by the Flash Player?

                 Do I need some import statement in my AS class or some liberaries are missing?

             

            And there is another one problem. Everything work fine for this function call:

             

                 var rooms:Object = remoteObject.echo1(myDupa);

             

            But for this function call:

             

            var rooms:Dupa = remoteObject.echo1(myDupa);

             

            I receives this error:

             

            TypeError: Error #1034: Type Coercion failed: cannot convert mx.rpc::AsyncToken@2708d041 to test.Dupa.

             

             

            It means, in my opinion, that received object's type is :AsyncToken. How can i get my Dupa object from it.

            • 3. Re: Conversion between ASObject and custom Java object
              tomj Adobe Employee

              If you are not using Flex, then the hooks are not executed.

               

              Tom Jordahl

              • 4. Re: Conversion between ASObject and custom Java object
                Rohit . Kumar Adobe Employee

                The Flex compiler ultimately converts the metadata tags into AS code during compilation. In case of [RemoteClass], it rougly gets converted to the what I wrote in my earlier response.

                 

                As regards the second question, here you can get access to the result of the RemoteObject.

                 

                var token:AsyncToken = remoteObject.echo1(myDupa);

                token.addAsyncResponder(resultFunc, faultFunc));

                 

                public function resultFunc(r:ResultEvent, t:Object = null) {

                      room = r.result as Room;

                }

                 

                public function faultFunc(f:FaultEvent, t:Object = null) {

                        ...

                        }

                 

                Rohit