8 Replies Latest reply on Apr 2, 2008 11:53 PM by DoonRothmani

    HTTP Service Trouble

    mrhalverson
      I am trying to access data binded to an object from a result of an httpservice. In the below example of the problem I am having, if var = Info.XMLMainTag.XMLSubTag; is removed the httpservice retrieves the data in lastresult and the Bind function is fired. But if var = Info.XMLMainTag.XMLSubTag; is put in, the Bind function is never called and from debugging it seems like the httpservice is never executed as the lastresult object is always null. I'm confused as to why this would happen? Any help is appreciated, thanks!

      <mx:Window xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" backgroundColor="#E7E7E7">

      <mx:HTTPService id="httpCreateJob" url=" http://localhost/debug/php/CreateJob.php" useProxy="false" method="POST" result="Bind(event);"/>
      <mx:Button label="Create Job" click="fncCreateJob();"/>

      <mx:Script>
      <![CDATA[

      import mx.rpc.events.ResultEvent;
      public var Info:Object;

      private function fncCreateJob():void {
      httpCreateJob.send();

      var Blah:String;
      var = Info.XMLMainTag.XMLSubTag; // if this is removed it works fine
      }

      private function Bind(event:ResultEvent):void {
      Info = event.result.CreateJobsResult;
      }

      ]]>
      </mx:Script>

      </mx:Window>
        • 1. Re: HTTP Service Trouble
          ntsiii Level 3
          "var = Info.XMLMainTag.XMLSubTag;" That is wrong. I am surprised it even compiles! I am sure you mean:
          Blah= Info.XMLMainTag.XMLSubTag;

          Tracy
          • 2. Re: HTTP Service Trouble
            ntsiii Level 3
            Addl info: the HTTPService does not get called until the "fncCreateJob" function ends (actually in the next frame, I think) And I believe the bad syntax is creashing the app. Surprised you are not getting errors.

            By the way, what are you trying to do with that line?
            Tracy
            • 3. Re: HTTP Service Trouble
              mrhalverson Level 1
              oh no I mean Blah= Info.XMLMainTag.XMLSubTag; It doesn't work with that, it is really strange, for some reason trying to access the data of the object after calling the http send makes the httpservice not even return an object into lastresult, it is just null. But if it is removed httpservice works fine...very strange
              • 4. Re: HTTP Service Trouble
                mrhalverson Level 1
                Basically i am trying to make it so after I call the httpCreateJob.send() I can check values of the results and do things based on those results. So the httpservice doesn't get called until the very end? Because in my full code I have other functions being called after the httpCreateJob.send() and using the Info object, but obviously the object is null. But if I remove any code having to do with that Info object AFTER the httpCreateJob.send() then it does work, but that isn't useful because I need my results! Dunno what is going on..thanks for the help
                • 5. HTTP Service Trouble
                  mrhalverson Level 1
                  If the httpservice doesn't get called until the next frame that would make sense as to why all the code after the call is executed before the service is actually called resulting in those null values...any work around?

                  EDIT:
                  I guess it is easy to work around now that I know how the httpservice works, just kind of strange
                  • 6. Re: HTTP Service Trouble
                    ntsiii Level 3
                    *All* data service calls are asynchronous. You can NEVER access the rsult in the same function in which you invoke send, You must use a result handler to access the results. You already have this in your Bind function. You must do all work starting there.

                    Tracy
                    • 7. Re: HTTP Service Trouble
                      DoonRothmani
                      tracy you are absolutely correct. i scratched my head for about 3 weeks when i first started dealing with asyncronous requests. couldnt figure out the "strange" results i was getting when things didnt seem to execute in the correct order. mhalverson you need to read about and understand asyncronous requests, and event listeners.
                      • 8. Re: HTTP Service Trouble
                        DoonRothmani Level 1
                        once you understand asynchronous requests and event listeners, everything will make sense to you.