3 Replies Latest reply on Feb 25, 2010 12:00 AM by eddjcaine

    n00b question - XML import woes


      Hey All,


      Am fairly new to Flex - having trouble getting my head round XML imports using HTTPRequest - have the following code:


      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundAlpha="0"

      initialize = "playlist.send()">




      import mx.collections.ArrayCollection;

      import mx.rpc.events.ResultEvent;




      private var plist:ArrayCollection;


      private function resultHandler(event:ResultEvent) :void {


      plist = event.result.playlist.tracklist;






      <mx:HBox paddingBottom="10" paddingTop="10" paddingLeft="10" paddingRight="10" horizontalGap="20">





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


      <mx:DataGrid dataProvider="{plist}" width="100%" height="100%" />




      for some reason, although when debugging with breakpoint at end of resultHandler() the event seems to indicate that the XML file was imported, plist remains stubbornly set to null - any ideas why?




        • 1. Re: n00b question - XML import woes
          saisri2k2 Level 4

          For the httpService add an parameter resultFormat as e4x (that would return yu xml in good format). Make the plist as public for u to be save.


          if 'playlist' is the root element of the XML then remove that from the following line


          plist = event.result.playlist.tracklist;


          make it to


          plist = event.result.tracklist;


          Hope it should help

          • 2. Re: n00b question - XML import woes



            Will you try this?


            private function resultHandler(event:ResultEvent) :void {


            plist = new ArrayCollection(mx.utils.ArrayUtil.toArray(event.result.playlist.tracklist));



            please update me it is correct or not?




            • 3. Re: n00b question - XML import woes
              eddjcaine Level 1

              Hey guys,


              Thanks for the answers - actually the problem was a little more simple than that - here is my XML data:


              <playlist version="1" xmlns="http://xspf.org/ns/0/">

                   <title>Edward Caine Pieces</title>






                             <creator>Tous les matin du monde</creator>

                             <title>Ossian Ensemble, Late Music Concert Series, 7/11/09</title>




                             <album>Late Music Concert Series 09</album>






              As you can see - I mis-spelled "trackList" (it has a capital L) - doh! rookie mistake!

              All sorted now - many thanks guys!