4 Replies Latest reply on Mar 19, 2012 10:04 AM by kokorito

    Value Objects and AMFPHP issues!

    l33tian Level 1

      Hello all...i'm a newbie when it comes to flex/flash Remoting...I have been using AMFphp for quite a while but my recent projects didnt need strong typed objects not until now! I tried doing it the lazy way, you know, by just passing the result object from the RemoteObject Service into an array like i have always done in the past. this is how i do it from the resultEvent callback function.

       

       

      var Units:ArrayCollection = new ArrayCollection(event.result as Array)
      

       

      The Result Returned is an Array of Objects but flex receives it as an object containing an array of objects which is why i am casting it in the line above.

      This arrayCollection is meant to act as a data provider for a list i built with a custom item renderer which displays it items using properties of the objects contained in the array. But i'm getting this annoying "unable to bind to property 'xxxxx_xxxx' on class 'Xxxxx' (class is not an IEventDispatcher). Any help will be appreciated as i'm suspecting my problem has something to do with Object proxies, RemoteClass Metetags, and explicit types!..help!

        • 1. Re: Value Objects and AMFPHP issues!
          PierreSolutions

          The lazy way might not work in this situation. You may have to loop through event.result and assign each object to an instance of a locally defined class that you add to your array collection. Just a few more lines of code.

           

          I think if you need to use dataBinding you will have to define the class of the objects in the array and in that class definition, you need to indicate [Bindable].

           

          Then, you should be able to use dataBinding on the instances of that class.

           

          for (var i:int = 0; i< event.result.length; i++)

                                                            {

                                                                      var rec:VOMyClass = new VOMyClass();

                                                                      rec = parseMyClass(event.result[i]); // or maybe rec = event.result[i] as VOMyClass ...

                                                                      Units.addItem( rec );

                                                            }

          1 person found this helpful
          • 2. Re: Value Objects and AMFPHP issues!
            l33tian Level 1

            Thanks Pierre, you're a saviour! I dont know why i didnt think of that on time!

             

            But one quick question...

             

            Dont you think it would have performance draw backs...what if i'm returning a thousand objects from the remote service. Note that. The RemoteObject is being requested every 40 seconds, so during every 40 seconds, my list gets updated with new units. ( I'm doing a GPS tracker in which a small flex Android App in sends details of the mobile device's location every 60 seconds to a mysql database. then a flex application reads this data and pin points its location. I'm using Google maps 3D API for flash to Achieve this). The system has been created in such a way that as more mobile phones join the system, the flex app is able to know and mark its location on the map...I'm trying to simulate real time mapping.

             

            Please tell me what you think and how i can make this better!

            • 3. Re: Value Objects and AMFPHP issues!
              PierreSolutions Level 2

              If all the Objects in the arrays you are getting down are as simple as GPS location records (Lat, Long, ID) then the parsing should not affect you too much.

               

              You may be getting thousands of records down the first time, but there would be no reason to get thousands of records each time, if you make your automatic call smart enough to only ask for new data (so ask the MySQL DB for records newer than the last time I got records) then you are lessening the number or records you get down, and you can just keep appending the new records to the arrayCollection.

               

              If performance is an issue, then you may want to define the Objects on the server in a way that Flex can automatically detect & deserialize on the client, AMFPHP and ZendAMF support this.

              • 4. Re: Value Objects and AMFPHP issues!
                kokorito Level 4

                for incoming objects you can just use a remote class alias

                to pass typed objects in both directions you need to map the class in the gateway

                 

                Wade Armold explains it nicely for zend amf, I guess it will work for amfphp

                 

                http://www.screencast.com/t/p4hpcV9a8H