8 Replies Latest reply on Nov 12, 2007 7:10 AM by pc_acke

    HTTPService access xml files

    rossrogerb
      Hello,

      I am New to Flex2 and still reviewing the training videos, Flex 2 Essentials and Beyond the basics.
      I am trying to ready an xml file I created based on the example in the video.
      The sample application I am using compiles clean but returns nothing when run in the browser.

      I may ask some obvious questions, but I am coming from a C/S background and have not worked much with browser based applications, so all of this is new to me....

      Is there something that needs to be installed in order for me to make a httpservice call?

      Using Winxp pro Flex2 CF 7.0 I installed the default CF web server. Also IIS is running, not sure if I need both!

      I want to be able to import xml files into a grid or other controls before moving onto access data from a DB.

      Thank you,

      Roger


        • 1. HTTPService access xml files
          187_2007 Level 1
          Nothing needs to be installed in order for the HTTPSERVICE call to be used.

          This my help you.

          http://www.adobe.com/devnet/coldfusion/articles/integrate_flex.html

          Flex2 works really really well with XML docs. If you get a chance buy this book. This is what I am using and it is very helpful and easy to follow.

          http://www.amazon.com/Adobe-Flex-2-Training-Source/dp/032142316X/sr=8-1/qid=1168963300/ref =pd_bbs_sr_1/102-6074363-0885736?ie=UTF8&s=books
          • 2. Re: HTTPService access xml files
            ntsiii Level 3
            ditto, the above.

            Additionally, I advise using resultFormat="e4x", and using a result handler function, because binding directly to a result is hard to debug.

            Tracy
            • 3. Re: HTTPService access xml files
              rossrogerb Level 1
              Thank you... Yes I have that book. I will look at the example on using xml files with Flex and see if it solves my problem.
              This seems like it should be a simple task so I must be doing something wrong!

              Roger

              • 4. Re: HTTPService access xml files
                ntsiii Level 3
                It IS simple, once you know how to do it! Post some code if you get stuck.

                And your incremental approach is solid.

                Tracy
                • 5. Re: HTTPService access xml files
                  rossrogerb Level 1
                  Tracy,

                  The code is right out of the Flex2 Essential training material. I just changed a few things to point to my xml file.

                  here is my code:

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

                  <mx:Script>
                  <![CDATA[
                  import mx.collections.ArrayCollection;
                  import mx.rpc.events.ResultEvent;

                  [Bindable]
                  private var myData:ArrayCollection;

                  private function resultHandler(event:ResultEvent):void {
                  myData = event.result.ZipCodes.Zipcode;
                  }
                  ]]>
                  </mx:Script>

                  <mx:HTTPService id="myService"
                  url="data/zipcodes100.xml"
                  result="resultHandler(event)"/>

                  <mx:DataGrid dataProvider="{myData}" width="350" height="500" x="41" y="10">
                  <mx:columns>
                  <mx:DataGridColumn dataField="zip" headerText="Zip Code" width="100"/>
                  <mx:DataGridColumn dataField="city" headerText="City" width="150"/>
                  <mx:DataGridColumn dataField="country" headerText="Country" width="100"/>
                  <mx:DataGridColumn dataField="areaCode" headerText="Area Code" width="150"/>
                  <mx:DataGridColumn dataField="state" headerText="State" width="75"/>
                  </mx:columns>
                  </mx:DataGrid>


                  </mx:Application>


                  Also a sample of the xml file I am trying to import:

                  <?xml=version="1.0"?>
                  <ZipCodes>
                  <Zipcode>
                  <zip>00501</zip>
                  <city>Holtsville</city>
                  <country>SUFFOLK</country>
                  <areaCode>631</areaCode>
                  <state>NY</state>
                  </Zipcode>
                  <Zipcode>
                  <zip>00544</zip>
                  <city>Holtsville</city>
                  <country>SUFFOLK</country>
                  <areaCode>631</areaCode>
                  <state>NY</state>
                  </Zipcode>
                  <Zipcode>
                  <zip>00601</zip>
                  <city>Adjuntas</city>
                  <country>ADJUNTAS</country>
                  <areaCode>787</areaCode>
                  <state>PR</state>
                  </Zipcode>
                  </ZipCodes>
                  • 6. Re: HTTPService access xml files
                    rossrogerb Level 1
                    part of the problem was I was working in a files called HTTPServiceZipCodes.xml but I did not have a HTTPServiceZipCodes.html file.... I do have a ZipCode.html file so I copied the code into the ZipCode.mxml and compiled it. In the browsers I do get a grid with the columns back but no data...
                    • 7. Re: HTTPService access xml files
                      rossrogerb Level 1
                      This may seem like a dumb question, but is there a limit to the number of records you can import from an xml file?
                      • 8. Re: HTTPService access xml files
                        pc_acke
                        Hi,

                        I am trying to do the same as you and end up with no data and an error message like:

                        TypeError: Error #1009: Cannot access a property or method of a null object reference.
                        at ReadXMLfile/::resultHandler()
                        at ReadXMLfile/__myService_result()
                        at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
                        at flash.events::EventDispatcher/dispatchEvent()
                        at mx.rpc.http.mxml::HTTPService/ http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()
                        at mx.rpc::AbstractInvoker/ http://www.adobe.com/2006/flex/mx/internal::resultHandler()
                        at mx.rpc::Responder/result()
                        at mx.rpc::AsyncRequest/acknowledge()
                        at ::DirectHTTPMessageResponder/completeHandler()
                        at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()

                        Do you get the same error?

                        The xml file is saved directly under the project and looks like this:

                        <?xml version="1.0" encoding="UTF-8"?>
                        <!DOCTYPE ROOT SYSTEM "Variables.dtd">
                        <ROOT xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance">
                        <row>
                        <field name="id">131130</field>
                        <field name="type">0</field>
                        <field name="ord">9</field>
                        <field name="diy">678</field>
                        <field name="title">*Prof</field>
                        <field name="heading">0</field>
                        </row>
                        <row>
                        <field name="id">132048</field>
                        <field name="type">2</field>
                        <field name="ord">61</field>
                        <field name="diy">688</field>
                        <field name="title">/Q11b Message recall - Dynepo</field>
                        <field name="heading">0</field>
                        </row>
                        </ROOT>
                        Regards
                        /Acke