6 Replies Latest reply on Aug 13, 2008 6:07 PM by vikceo

    How to get result of HTTPService within a function?

    Hamshmam
      Hello all,

      I'm trying to call an HTTPService's send() and get the resulting data from within a function, and assigning it locally. Specifically, this is what I want:

      private function getData():void {
      myRPC.send();
      //How do I set the result of myRPC.send to a variable here?
      // Neither myRPC.send().result, nor myRPC.lastResult works! I get null both times!
      // But if I set myRPC.result to a separate function that handles an event, I get the correct data...but not what I want.
      var myObject:Object = ???? myRPC.???
      }

      <mx:HTTPService result="???" fault="???" id="myRPC" method="GET" resultFormat="e4x" url="someurl" useProxy="false">
      <mx:request xmlns="">
      <somedata>hi</somedata>
      </mx:request>
      </mx:HTTPService>

      I am also not sure what to put in 'result' and 'fault' since I don't want the result/fault to be passed to another function...could anyone explain this please? Thanks!
        • 1. Re: How to get result of HTTPService within a function?
          Gregory Lafrance Level 6
          Here is a simple example of using HTTPService. Best not to use lastResult, but instead to use a result event handler.
          • 2. Re: How to get result of HTTPService within a function?
            Hamshmam Level 1
            Hi Greg,

            While this is not what I am looking for, thanks for your response.

            I am familiar with traditional HTTPService requests and passing the resulting event to a function handle directly and then modifying the object from there. However, as I described in my earlier post, I'm looking for a way to get the resulting event of the HTTPService.send() within a different function.

            I am doing this because if I have another function dependent on the HTTPService.send()'s data, I cannot simply call the HTTPService.send() from within that function and update a class private var with the data, which I access from the wrapping function. This is because the HTTPService is by nature asynchronous, so it is possible that the class private var will remain null while further lines of code are executed, all the while the HTTPService is interacting with the server concurrently.

            I hope it is clear now why I need to assign the result of a HTTPService result directly within a function, if you or anyone else could shed some light on that, I would appreciate it! Thanks for your response.
            • 3. Re: How to get result of HTTPService within a function?
              Gregory Lafrance Level 6
              Because HTTPService is asynchronous, you can't get its value in a function. But you can call that other function from the HTTPService resultHandler, and pass that function the data. I know you want to use that function to "send" the HTTPService, but even then you could break it into two functions, one to call send() and the other that gets called from the resultHandler. Just a thought... :-)
              • 4. Re: How to get result of HTTPService within a function?
                Level 7

                "Hamshmam" <webforumsuser@macromedia.com> wrote in message
                news:g70olu$jcd$1@forums.macromedia.com...
                > Hi Greg,
                >
                > While this is not what I am looking for, thanks for your response.
                >
                > I am familiar with traditional HTTPService requests and passing the
                > resulting
                > event to a function handle directly and then modifying the object from
                > there.
                > However, as I described in my earlier post, I'm looking for a way to get
                > the
                > resulting event of the HTTPService.send() within a different function.
                >
                > I am doing this because if I have another function dependent on the
                > HTTPService.send()'s data, I cannot simply call the HTTPService.send()
                > from
                > within that function and update a class private var with the data, which I
                > access from the wrapping function. This is because the HTTPService is by
                > nature
                > asynchronous, so it is possible that the class private var will remain
                > null
                > while further lines of code are executed, all the while the HTTPService is
                > interacting with the server concurrently.
                >
                > I hope it is clear now why I need to assign the result of a HTTPService
                > result
                > directly within a function, if you or anyone else could shed some light on
                > that, I would appreciate it! Thanks for your response.

                http://www.johnwilger.com/2007/03/future-value-pattern-in-actionscript-3.html


                • 5. Re: How to get result of HTTPService within a function?
                  Hamshmam Level 1
                  Thanks everyone! I ended up just chaining the HTTPService.send() calls within each other, which works.
                  • 6. Re: How to get result of HTTPService within a function?
                    vikceo
                    can u elaborate how u did that? please paste some sample code too if possible