1 Reply Latest reply on Jun 21, 2008 9:43 AM by raymond_domingo

    Flex and Java Objects (and Flex Tree)

    raymond_domingo Level 1
      Hello,

      I'm trying to fill my flex tree using the data returned from my webservice...

      My Webservice is called findPersons and returns an array of persons (containing firstName and lastName properties).

      When I add myService.findPersons.lastResult as the dataProvider of my tree I just see Object in my tree, after adding the labelFunction attribute to my tree I could specify the firstName from the object should be used as my label. This is exactly what I need. The code looks like:

      private function readLabel(item:Object):String {
      return item.firstName;
      }

      BUT, when my tree contains two types of objects, let's say objects of type:
      - person
      - adress

      Is there any way I can find out the type of the object. So in java I have Person and Address, but as far as I see in Flex I can't retrieve the java's object type. I would like to do something like:

      private function readLabel(item:Object):String {
      if (item instanceof Person) {
      return item.firstName;
      } else if item instanceof Address) {
      return item.city;
      } else {
      return "unknown";
      }
      }

      I know I can use resultFormat="e4x" but then I have to do all the handling my self and I don't bennefit from my Java object structure.

      PS: I'm looking for more information/examples about Flex and Java Object types / Flex Trees and Webservices, etc


      Best regards,
      Raymond