3 Replies Latest reply on Apr 28, 2009 10:59 AM by Barna Biro

    This and that


      This problems appears to occur somewhat inconsistently, it's hard to reproduce outside of the context of the entire project.


      I'm using RemoteObjects to call a method on a java backend, and I pass it a copy of the calling class. This works fine in most cases, but more and more often I get a message like this from my application server that's running the java backend:


      [Flex] [ERROR] Error handling message: flex.messaging.MessageException: Cannot invoke method 'myMethod'. The expected argument types are (myPackage.myDestinationClass) but the supplied types were (flex.
      messaging.io.amf.ASObject) and converted to (null).


      The problem seems to point to the use of "this" in a line such as this one:




      but sometimes the this seems to refer to something other than the current object.If I do the following, I have no problem:


      var _this : * = this;



      I can't seem to figure out why there's a difference. Doesn't "this" get evaluated before the method is even called?


      If anyone has any tips or leads, they would be greatly appreciated! Thanks.

        • 1. Re: This and that
          Barna Biro Level 3

          Hi there,


          The main difference between using "this" and storing a reference to it of a generic type is the actual type you are working with. Let's say you have a class BlueCar, if you define public a method in BlueClar that simply does a return of: return this; and call that method later on then "this" will actually return the instance of the class of type BlueCar. If you do var _this:* = this; and return _this; then the type of the returned object will be * ( meaning Object ) which is a generic type. This might be the problem, your server-side script does not know what to do with the conrete type but it can treat the generic type because it's generic ( in most cases, it won't convert the object to a known and correct type but at least it won't throw an error if it receives a generic object instead of a custom type like BlueCar because it has no knowledge of a type called "BlueCar" so it has no idea what to do with it, then, it throws an error saying that it can't convert type X to type Y ).


          That would be in short. For more information, you should definitely read up on RemoteObjects in livedocs and look for some "real world" examples that teach you how to send an object of a concrete type to a server-side script so that the server can recognize it ( usually, this is done with the help of mapping ).


          With best regards,

          Barna Biro


          PS: the "cannot invoke method" error is cause by the same thing, since the received object is seen as a generic object then your server-side scrip has no knowledge of a method called "myMethod". Again, read up on RemoteObject and on mapping.

          • 2. Re: This and that
            MackrorySD Level 1

            On the contrary - sending a generic type is when I _don't_ have a problem. I have a problem when I place a direct reference to "this" in the method parameters. If I declare a new var (whether it's generic or typed to the object in question) and initialize it to this, and pass that in, I have no problem.

            • 3. Re: This and that
              Barna Biro Level 3

              Sorry, I was trying to say the same thing just that I forgot to delete pieces of my PS and somehow it ended up to be the exact contrary of what I've been saying until then ( English is not my first language, sorry ). As I said, the problen is caused because your server-side script does not recognize the type of your object if you send it as a concrete type and not a generic type. Read up on mapping and you should be able to solve the problem.


              With kind regards,

              Barna Biro