4 Replies Latest reply on Jun 17, 2010 7:04 AM by xpsdeset

    UserService response to array

    xpsdeset

      I am very new to flex.

       

      Now

      getChatsResult.token = usersService.getChats();

      The line generates token I want is that the result generated by the service

       

      i want to format the result in an array of objects an example would be helpfull.

      i mean

       

      var chats:Array = usersService.getChats();

       

      for(i=0;i<chats.length;i++)

      {

      text.Text+=chat[i]["chat"]+"\n";

      }

       

      But the above is not working.

        • 1. Re: UserService response to array
          BhaskerChari Level 4

          Hi,

           

          You need to add the responder for the asyncToken...that means that you need to register response and fault handlers on asyncToken object.See the below code:

           

          var asyncToken:AsyncToken = usersService.getChats();


             asyncToken.addResponder(new mx.rpc.Responder(
              function result(result:ResultEvent):void
              {
                  var chats:Array = result.result; // try to analyse here the result variable and manipulate the code here accordingly..

             },
              function fault(event:FaultEvent):void
              {
               Alert.show(event.fault.faultString);
              }
              ));

           

          Note: It's always a good practice to register eventHandlers for an asynchronous operation.

           

          If this post answers your question or helps, please kindly mark it as such.


          Thanks,

          Bhasker Chari

          1 person found this helpful
          • 2. Re: UserService response to array
            xpsdeset Level 1

            Thanks a lot Bhasker Chari for your reply.

            Sorry I am a newbie at flex.

             

            Below is my code its givingfollowing errors

             

            Type was not found or was not a compile-time constant: AsyncToken.
            Type was not found or was not a compile-time constant: FaultEvent.
            Type was not found or was not a compile-time constant: ResultEvent.

             

            <s:CallResponder id="getChatsResult"/>

             

             

            I even imported

                        flash.events.Event


            protected function ChatSend_keyDownHandler(event:KeyboardEvent):void
                        {
                           
                                getChatsResult.token = usersService.getChats();
                               
                               
                                //var asyncToken:AsyncToken = usersService.getChats();
                               
                               
                                getChatsResult.addResponder(new mx.rpc.Responder(
                                    function result(result:ResultEvent):void
                                    {
                                        var chats:Array = result.result; // try to analyse here the result variable and manipulate the code here accordingly..
                                       
                                    },
                                    function fault(event:FaultEvent):void
                                    {
                                        Alert.show(event.fault.faultString);
                                    }
                                ));
                  }//end of function


            • 3. Re: UserService response to array
              BhaskerChari Level 4

              Hi,

               

              You need to import the namespaces in your page.

               

              import mx.rpc.AsyncToken;
              import mx.rpc.Responder;
              import mx.rpc.events.FaultEvent;
              import mx.rpc.events.ResultEvent;

               

              It seems that you are using the Flex4...any way try to import these namespaces if this namespaces are not recognised try to use the namespaces relevant in Flex4.


              If this post answers your question or helps, please kindly mark it as such.


              Thanks,

              Bhasker Chari

              • 4. Re: UserService response to array
                xpsdeset Level 1

                Thanks a Lot Bhasker Chari you  made my day.