1 Reply Latest reply on May 8, 2007 4:38 PM by ntsiii

    HTTPService Problems

    solomonmine
      I am a total newbie to Flex and i am trying to create a simple chart
      the populates from a database, I am pulling the data from the DB
      using PHP script. The scrip works fine. the problem i am having is
      when i try to assign the value to a variable the whole page come back
      as as blank.

      public var leaveused:Number =
      leavedetails.lastResult.leaveinfo.leave.leavestdate;

      I know this is the problem because when i use static values the chart
      is displayed. I can assign the value above to a text.text and it gets
      displayed fine.

      Guys please help as i was dumb enough to try to do something i have
      never done b4 as a final uni project.

      Chimera
        • 1. Re: HTTPService Problems
          ntsiii Level 3
          That assignment has several problems. First, the result of the data service call does not exist when the variable is declared. SEt it instead in a result handler on your data service call. Don't use lastResult. Call trace to se what your data looks like.

          See the sample code below.

          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;

          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

          Tracy