4 Replies Latest reply on May 29, 2007 8:30 AM by Dan McAdam

    HTTPService issues

    Dan McAdam
      I'm having difficulty in getting a simple HTTPService call to work

      I've got a simple MySQL DB, using one table with 3 records and 3 fields

      I'm evaluating Flexbuilder 2 and can't seem to construct a valid result

      My PHP page call returns the following XML:
      *****************************************************
      <jobfamilies>
      <job>
      <jobid>1</jobid>
      <surveyid>1</surveyid>
      <familyname>Accounting</familyname>
      </job>
      <job>
      <jobid>2</jobid>
      <surveyid>1</surveyid>
      <familyname>Bookeeping</familyname>
      </job>
      <job>
      <jobid>3</jobid>
      <surveyid>1</surveyid>
      <familyname>Construction</familyname>
      </job>
      </jobfamilies>
      *******************************

      My MXML code looks like this:
      *******************************************
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute"
      initialize="initializeHandler(event)" >
      <mx:Script>
      <![CDATA[
      import mx.rpc.xml.XMLDecoder;
      private function initializeHandler(event:Event):void {
      myjobs.send( );
      }
      private var myxml:XML = myjobs.lastResult.toString();

      ]]>
      </mx:Script>
      <mx:HTTPService id="myjobs"
      url=" http://myhostedserver.com/cea/admin_jobs.php" />
      <mx:VBox>
      <mx:TextArea text="myxml" width="300" height="300" />
      </mx:VBox>

      </mx:Application>
      ******************************************

      just trying to make a connection and get a return
      gotta start somewhere <8-)
        • 1. Re: HTTPService issues
          skarkar
          so, where're you stuck at? Does the php script print any debug output showing that it actually sends this xml to flex?

          Also, add code to print the result from the httpresult call, like "trace" it.
          • 2. Re: HTTPService issues
            ntsiii Level 3
            See the sample code below. Note especially the resultFormat and the use of a result handler function.
            Tracy

            Sample code using HTTPService, e4x, handler function to populate a list item

            The DataGrid tag:
            <mx:DataGrid id="dg" dataProvider="{_xlcMyListData}" .../>


            The HTTPService tag:
            <mx:HTTPService id="service" resultFormat="e4x" result="onResult(event)" fault="..../>

            Script block declaration:
            import mx.rpc.Events.ResultEvent;
            [Bindable]private var _xlcMyListData:XMLListCollection;

            Invoke send:
            var oRequest:Object = new Object();
            oRequest.Arg1 = "value1";
            service.send(oRequest);

            Result Handler function:
            private function onResult(oEvent:ResultEvent):void {
            var xmlResult:XML = XML(event.result); //converts result Object to XML. can also use "as" operator
            var xlMyListData:XMLList = xmlResult.myListData; //depends on xml format, is row data
            _xlcMyListData = new XMLListCollection(xlMyListData); //wrap the XMLList in a collection
            trace(_xlcMyListData.toXMLString()); //so you can see exactly how to specify dataField or build labelFunction

            }//onResult
            • 3. Re: HTTPService issues
              ntsiii Level 3
              "Does the php script print any debug output showing that it actually sends this xml to flex?" right, hit the php page directly from a browser to verify.
              Tracy

              BTW, this is not the correct forum for Flex language questions. They should go in General Discussion.
              • 4. Re: HTTPService issues
                Dan McAdam Level 1
                thanks very much for the example code... gives me a good insight
                I got my datagrid to populate by including an XML header declaration in the PHP output string... I thought Actionscript would just use straight XML in an XML typed object...

                I'm working my way through the "Programming Flex2" book by Kazoun and Lott, which is helping alot...

                do you know the preferrable way to pass XML data to a PHP (or ASP whaterver) script?... just send it as a string and type and parse it on the server? was hoping there might be a more elegant solution...

                thanks again