4 Replies Latest reply on Mar 7, 2012 6:17 AM by david_kenneth_coleman

    Handling HashMap from a RemoteObject call

    Giri s
      Hi,

      I am trying to get HashMap from a remote Object call and to display in a DataGrid .I am using HashMap
      http://www.ericfeminella.com/blog/2006/12/08/as3-util-api-available/.

      The RemoteObject method returns a HashMap, but from the result event, if iam trying to cast it to HashMap it is returning null.

      If iam trying to get the HashMap as a Object, trying to retrieving the key value fairs

      if(obj!= null){
      for (var key:String in obj) {
      Alert.show(" Key ="+key+" Value ="+obj[key]);
      }
      }

      it is not displaying anything.

      Any clues on how to get the HashMap data and display it in a DataGrid.

      Thanks,
      Giri
        • 1. Re: Handling HashMap from a RemoteObject call
          ntsiii Level 3
          If you look at event.result in the debugger, or inspect it using ObjUtil.toString(), what do you see?
          Tracy
          • 2. Re: Handling HashMap from a RemoteObject call
            Giri s Level 1
            Hi Tracy,

            Please find the ObjectUtil.toString(result) below:

            • 3. Re: Handling HashMap from a RemoteObject call
              SujitG Level 2
              Hi,

              There is no data type or Class called HashMap in ActionScript. HashMap returned from Java will be converted to an Object in ActionScript. All keys of the HashMap will be properties of the Object and the values will be values of the properties.

              Please find the conversion table at the URL below.

              http://livedocs.adobe.com/flex/3/html/data_access_4.html#202412

              DataGrid will accept a collection of Objects, you can create a collection using the Object received and give it to the DataGrid.

              Hope this helps.
              • 4. Re: Handling HashMap from a RemoteObject call
                david_kenneth_coleman Level 1

                sometimes an object is not actually an object but an object proxy.  Try this code below:  (where data is yor original object)

                 

                var _data:Object;
                if(data is ObjectProxy) {
                    _data = (data as ObjectProxy).object_proxy::object;
                } else {
                    _data = data;
                }
                // do something with the object now
                

                 

                This works for me when i run into the problem of not being able to walk through an object.  also you can try to use XML to step through the accesors.

                          protected static function foo (objToWorkWith:*):Bar (whatever you need it to return) {
                               var obj:Object = new Object();
                               var xml:XML = describeType(objToWorkWith);
                               if(xml.@name == "Object") {
                                    for (var i:* in objToWorkWith) {
                                         // do something
                                    }
                               } else {
                                    if((xml..variable).length && (xml.extendsClass.@type[0] == "Object")) {
                                         for each(var variable:* in xml..variable) {
                                              var var_name:String = variable.@name;
                                              var var_type:String = variable.@type;
                                              var var_value:* = variable.@value;
                                                                // do something
                                         }
                                    } else {
                                         for each(var accessor:* in xml..accessor) {
                                              var name:String = accessor.@name;
                                              var type:String = accessor.@type;
                                              var value:* = accessor.@value;
                                              obj[name] = objToWorkWith[name];
                                         }
                                         for (var j:* in obj) {
                                              // do something
                                         }
                                    }
                               }
                               return somethingOrNothing_whateverYouNeed;
                          }