3 Replies Latest reply on Oct 19, 2009 10:55 AM by kabalweg

    No data from httpservice in datagrid

    mateuszef

      I wrote some code after first lesson from tutorial 'flex in one week' by Adobe. I want to populate instance of DataGrid with data from xml file. I use HTTPService class to do this. Here is my code:

       

      people.xml

      <people>
           <person>
                <name>Jan</name>
                <surname>Kowalski</surname>
                <age>20</age>
           </person>
           <person>
                <name>Andrzej</name>
                <surname>Nowak</name>
                <age>25</age>
           </person>
      </people>
      

      ex1.mxml

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
      
      
      <mx:Script>
           <![CDATA[
                import mx.collections.ArrayCollection;
                import mx.rpc.events.ResultEvent;
                import mx.rpc.events.FaultEvent;
                import mx.controls.Alert;
                import mx.events.DataGridEvent;
                
                [Bindable]          
                private var peopleList:ArrayCollection;
                
                private function init():void{
                     this.srv.send();
                }
                private function httpResultHandler(event:ResultEvent):void{
                     this.peopleList = event.result.people.person;
                }
                private function httpFaultHandler(event:FaultEvent):void{
                     Alert.show("There was a problem","Error");
                }
           ]]>
      </mx:Script>
      
           <mx:HTTPService id="srv" url="assets/people.xml" result="httpResultHandler(event)" fault="httpFaultHandler(event)"/>
           <mx:DataGrid x="0" y="0" width="100%" height="100%" id="dg" dataProvider="{peopleList}">
                <mx:columns>
                     <mx:DataGridColumn headerText="Name" dataField="name"/>
                     <mx:DataGridColumn headerText="Surname" dataField="surname"/>
                     <mx:DataGridColumn headerText="Age" dataField="age"/>
                </mx:columns>
           </mx:DataGrid>
           
      </mx:Application>
      
      

      Can someone take a look at my code and try to help me ?

       

      The result of it in my browser is alert which appears during carrying out the function httpFaultHandler, but I don't know why this function is executed..

       

      Thanks in advance