2 Replies Latest reply on Jan 18, 2010 4:58 AM by Ali_Hwth

    HTTPService, E4X and XML - the basics

    Ali_Hwth

      Hi all,

      I'm trying to get started with Flex but I've run inot a problem loading data from XML into my application.

      All I'm trying to do is pull the firstName into a textbox.

       

      The first error seems to relate to syntax, and says that the closing </mx:windowedApplication> is missing...although it is not.

      On launching the application, I get an error which seems to focus on line 17

      And then the datagrid is not showing up at all.

       

      Can anyone point out where I'm going wrong, or, ideally, put up a completed example that I could refer to in future? I 'd be grteful for ever...

       

      So this is the XML:

      <?xml version="1.0" encoding="utf-8"?>
      <data>
          <donorDetails>
              <nameDetails>
                  <firstName>
                      Ali
                  </firstName>
                  <secondName>
                      Hurworth
                  </secondName>
              </nameDetails>
              <apptDetails appt="first">
                  <apptDate>
                      01052009
                  </apptDate>
                  <apptTime>
                      1735
                  </apptTime>
              </apptDetails>
              <apptDetails appt="second">
                  <apptDate>
                      03092009
                  </apptDate>
                  <apptTime>
                      1655
                  </apptTime>
              </apptDetails>
              <nSession>
                  <session>
                      Woodlands
                  </session>
                  <sessionPostcode>
                      DN6 4AQ
                  </sessionPostcode>
                  <postCode>
                      DN6
                  </postCode>
              </nSession>
          </donorDetails>
      </data>

       

      and this is the MXML:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:WindowedApplication
          xmlns:mx="http://www.adobe.com/2006/mxml"
          layout="absolute"
          creationComplete="donorDataLink.send()">
         
          <mx:HTTPService
              url="appt.xml"
              id="donorDataLink"
              resultFormat="e4x"
              result="resultHandler(event)" />
             
              <mx:Script>
                  <![CDATA[
                      import mx.controls.Alert;
                      import mx.rpc.events.FaultEvent;
                      import mx.rpc.events.ResultEvent;
                      import mx.collections.ArrayCollection;
              
                      [Bindable]
                      private var loadedData:ArrayCollection;
              
                      private function resultHandler(event:ResultEvent):void
                      {
                          this.loadedData = event.result.data.donorDetails.nameDetails.firstName;
                      }
              
                      private function faultHandler(event:FaultEvent):void
                      {
                          Alert.show("Error: " + event.fault.faultString, "Application Error");
                      }
                  ]]
              </mx:Script>

          <mx:VBox x="35" y="27" width="233" height="233">
          <mx:DataGrid x="10" y="10" dataProvider="{loadedData}" width="200"/>
              <mx:TextArea width="233" id="output_txt" text="result"/>
          </mx:VBox>
      </mx:windowedApplication>

      and this is the fault:

      TypeError: Error #1006: value is not a function.
          at xml1/__donorDataLink_result()[C:\Users\Main\Documents\Flex Builder 3\desko\src\xml1.mxml:17]
          at flash.events::EventDispatcher/dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at mx.rpc.http.mxml::HTTPService/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[E:\dev\3.0.x\frameworks\pro jects\rpc\src\mx\rpc\http\mxml\HTTPService.as:275]
          at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[E:\dev\3.0.x\frameworks\projec ts\rpc\src\mx\rpc\AbstractInvoker.as:191]
          at mx.rpc::Responder/result()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\rpc\Responder.as:4 1]
          at mx.rpc::AsyncRequest/acknowledge()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\rpc\AsyncR equest.as:74]
          at DirectHTTPMessageResponder/completeHandler()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\ messaging\channels\DirectHTTPChannel.as:381]
          at flash.events::EventDispatcher/dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at flash.net::URLLoader/onComplete()

      I don't think I'm miles away from where I need to be...but it appears to be a simple operation and I would like to do so much more.

      So any help would be totally gratefully received!

        • 1. Re: HTTPService, E4X and XML - the basics
          pauland Level 4

          Ali_Hwth wrote:

           

          Hi all,

          I'm trying to get started with Flex but I've run inot a problem loading data from XML into my application.

          All I'm trying to do is pull the firstName into a textbox.

           

          The first error seems to relate to syntax, and says that the closing </mx:windowedApplication> is missing...although it is not.

           

           

          Oh yes it is..

           

          and this is the MXML:

          <?xml version="1.0" encoding="utf-8"?>
          <mx:WindowedApplication
              xmlns:mx="http://www.adobe.com/2006/mxml"
              layout="absolute"
              creationComplete="donorDataLink.send()">
             

          </mx:windowedApplication>


           

          You MUST pay close attention to case and have more faith in what the compiler says!

           

          Paul

          1 person found this helpful
          • 2. Re: HTTPService, E4X and XML - the basics
            Ali_Hwth Level 1

            Thanks for your reply, Paul.

            I don't have Flex at work, so I will alter it when I get home.

             

            That said, am I on the right lines? Is that code going to pick out the firstName element and add it to the datagrid - or does it depend on returning at least two sets of results?

             

            Thanks in advance,

             

            Ali