5 Replies Latest reply on Feb 10, 2010 11:16 PM by luke3design!!

    Data not retrieving from an external file.

    Sreelash Level 1

      Hi,

       

           I am loading datas from an external file and displaying it in a datagrid. Actually it was working. But now when run the application the data is not binding in the datagrid. The code that i have used for this application is following:

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
          xmlns:comp = "components.*"
          layout="horizontal"
          backgroundGradientAlphas="[1.0, 1.0]"
          horizontalGap="15"
          backgroundGradientColors="[#7424242, #6F6F6F]"
          pageTitle="Company Employee Directory"
         initialize="employeeService.send()" >
         
          <mx:Script>
              <![CDATA[
                  import mx.collections.ArrayCollection;
                  import mx.rpc.events.ResultEvent;
                 
                  [Bindable] private var employeeData:ArrayCollection;
                  private function resultHandler(event:ResultEvent):void{
                      employeeData = event.result.employees.employee;
                  }

              ]]>
          </mx:Script>
         
           <mx:HTTPService id="employeeService"
              url="data/employees.xml"
              result="resultHandler(event)"/> 

               
          <mx:Panel title="Company Employees">   
              <mx:DataGrid dataProvider="{employeeData}"
                  alternatingItemColors="[#CCCCCC, #AAAAAA]" >
                  <mx:columns>
                      <mx:DataGridColumn dataField="firstname"
                          headerText="First Name" />   
                      <mx:DataGridColumn dataField="lastname"
                          headerText="Last Name"/>
                      <mx:DataGridColumn dataField="title"
                          headerText="Title" width="250"/>
                  </mx:columns>
              </mx:DataGrid>   
          </mx:Panel>
         
          <mx:Label id="test" color="#FFFFFF"/>
           
          <mx:VBox verticalGap="15">   
              <comp:employeeDetails />
              <comp:search/>
          </mx:VBox>
      </mx:Application>

       

      Can anybody help me to solve this. I think it may be a small issue. I am a newbie in Flex.

       

      Thanks and regards,

      Sreelash.

        • 1. Re: Data not retrieving from an external file.
          luke3design!!

          It could seems stupid, but the xml file is present?

           

          Another problem could be the result handler?

          To read the result :

           

            private function resultHandler(event:ResultEvent):void{
                          employeeData = event.target.lastResut.employees.employee;
                      }

           

          I'd also do :employeeData = new ArrayCollection(event.target.lastResut.employees.employee);

           

          'cause you're attempting to put an xml into and arraycollection.

           

          Then try also to run all in debug mode to see if some errors occours.

           

           

          bye!

          1 person found this helpful
          • 2. Re: Data not retrieving from an external file.
            Gregory Lafrance Level 6

            If you are processing XML data, its usually best to use XMLListCollection instead of ArrayCollection.

             

            Anyway, you should probably have resultFormat="e4x" in your HTTPService component:

             

            <mx:HTTPService id="employeeService" url="data/employees.xml" 

                result="resultHandler(event)" resultFormat="e4x"/> 

             

            Also, you may want this in the result handler method:

             

            private function resultHandler(event:ResultEvent):void{
                employeeData = ArrayUtil.toArray(event.result.employees.employee);
            }

            or this:

             

            private function resultHandler(event:ResultEvent):void{
                employeeData = ArrayUtil.toArray(event.result.employees.employee as XMLList);
            }

            If this post answers your question or helps, please mark it as such.


            Greg Lafrance - Flex 2 and 3 ACE certified

            www.ChikaraDev.com

            Flex / AIR Development, Training, and Support Services

            • 3. Re: Data not retrieving from an external file.
              Sreelash Level 1

              Hi Greg,

               

                  I updated the code as follows:

               

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                  layout="absolute"
                  initialize="employeeService.send()">
                  <mx:Script>
                      <![CDATA[
                          import mx.utils.ArrayUtil;
                          import mx.collections.XMLListCollection;
                          import mx.collections.ArrayCollection;
                          import mx.rpc.events.ResultEvent;
                         
                          [Bindable] private var employeeData:Array;
                          private function resultHandler(event:ResultEvent):void{
                              //employeeData = event.result.employees.employee;
                              //employeeData = ArrayUtil.toArray(event.result.employees.employee);
                              employeeData = ArrayUtil.toArray(event.result.employees.employee as XMLList);
                          }
                      ]]>
                  </mx:Script>
                 
                  <mx:HTTPService id="employeeService"
                      url="data/employees.xml"
                      result="resultHandler(event)"
                      resultFormat="e4x" />       
                     
                  <mx:DataGrid dataProvider="{employeeData}"   
                      width="100%" height="100%" />
              </mx:Application>

               

              But not working. Shall i make any other changes to it?

               

              Thanks and regards,

              Sreelash

              • 4. Re: Data not retrieving from an external file.
                Sreelash Level 1

                Hi luke,

                 

                I have updated the code with your suggestions. It's working. But when i tried to run in debug mode, an error shows which is following:

                 

                C:\WINDOWS\system32\Macromed\Flash\Flash10c.ocx


                Flex Builder cannot locate the required debugger version of Flash Player. You might need to install the debugger version of Flash Player 9 or reinstall Flex Builder.


                Do you want to try to debug with the current version?


                What should i do regarding this error?

                 

                Thanks and regards,

                Sreelash

                • 5. Re: Data not retrieving from an external file.
                  luke3design!! Level 1

                  This error is raised when you don't have the debugger version of flash player installed.

                   

                  To install it go here:

                   

                  http://www.adobe.com/support/flashplayer/downloads.html#fp10

                   

                  Then choose the debugger that suits your system (from the error you posted it seems your're on a Windows box so this could be your plugin, if using firefox: http://download.macromedia.com/pub/flashplayer/updaters/10/flashplayer_10_plugin_debug.exe )

                   

                  Hope this help ya!!!

                  Bye!!!