5 Replies Latest reply on Jun 8, 2006 8:18 AM by cjwprostar.

    HTTPService using e4x

    cjwprostar.
      I'm trying to use HTTPService to receive xml data from a website, using e4x, then put it in a datagrid (and do other things with it later). I can get it to populate the datagrid using object, but need it in xml form to use it in other places. I've tryed using an XMLListCollection, but can't seem to get it working.

      /********************* XML *******************/
      <?xml version="1.0" encoding="iso-8859-1" ?>
      <tool>
      <projects>
      <project>
      <projectName>Project 1</projectName>
      <active>true</active>
      </project>
      <project>
      <projectName>Project 2</projectName>
      <active>true</active>
      </project>
      </projects>
      </tool>


      /***************** This works ****************/
      <mx:HTTPService id="list_request" url="myxml.xml" showBusyCursor="true" resultFormat="object" fault="Alert.show('Project listing could not be retrieved!','Error');"/>
      <mx:DataGrid y="0" width="508" height="291" horizontalCenter="0" dataProvider="{list_request.lastResult.tool.projects.project}" id="dgProjects">
      <mx:columns>
      <mx:DataGridColumn headerText="Projects" dataField="projectName"/>
      </mx:columns>
      </mx:DataGrid>


      Thanks in advance.
        • 1. Re: HTTPService using e4x
          cjwprostar. Level 1
          Ok after alot more tinkering I found a way to do it...

          <mx:HTTPService id="list_request" url="{functionPageLocation}" showBusyCursor="true" resultFormat="e4x" fault="Alert.show('Project listing could not be retrieved!','Error');"/>

          <mx:DataGrid y="0" width="508" height="291" horizontalCenter="0" dataProvider="{list_request.lastResult.child('projects').child('project')}" id="dgProjects">
          <mx:columns>
          <mx:DataGridColumn headerText="Projects" dataField="projectName"/>
          </mx:columns>
          </mx:DataGrid>


          Is this the best way to do this?
          • 2. Re: HTTPService using e4x
            Level 7
            Instead of

            list_request.lastResult.child('projects').child('project')

            it is more common to just use this:

            list_request.lastResult.projects.project
            • 3. HTTPService using e4x
              cjwprostar. Level 1
              Using that I get these console warnings:
              warning: unable to bind to property 'projects' on class 'XML' (class is not an IEventDispatcher)
              warning: unable to bind to property 'project' on class 'XMLList' (class is not an IEventDispatcher)


              Also, I can't figure out why lastResult is returning null if I work with it in the same function list_request was called from.

              public function GotoStartPage():void{
              list_request.send();
              // If the query contained a value for project_request...
              if(Application.application.parameters.project_request!=null){
              // Check to see if the query matched one of the listed projects

              {
              project_request=Application.application.parameters.project_request;
              currentState="Main Project Page";
              }
              }else{
              trace(list_request.lastResult); // <- this gives null
              project_request="";
              currentState="Project Selection Screen";
              }
              }

              Is the trace statement getting called before list_request.send() is finished getting the data?
              • 4. Re: HTTPService using e4x
                ntsiii Level 3
                Data service calls are asynchronous.

                You CANNOT access the lastResult in the same function that you invoke send.

                You MUST use either binding or a result handler function run by the result event.

                See "Handling asynchronous calls to services" in the developers guide.

                Tracy
                • 5. Re: HTTPService using e4x
                  cjwprostar. Level 1
                  Thank you, that worked like I needed it to.