3 Replies Latest reply on Apr 11, 2011 4:47 AM by jexer

    Cant open a simple XML file.

    jexer Level 1



      This has probably been answered, but the search bar in the forum seems to be broken so I couldn't look for it.


      I tried to open an xml file with a simple app:


      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                     xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
                  import mx.rpc.events.FaultEvent;
                  import mx.rpc.events.InvokeEvent;
                  import mx.rpc.events.ResultEvent;


                  protected function srv_resultHandler(event:ResultEvent):void
                  { trace("result"); }


                  protected function srv_invokeHandler(event:InvokeEvent):void
                  { trace("invoke"); }


                  protected function srv_faultHandler(event:FaultEvent):void
                  { trace("fault"); }


                  protected function button1_clickHandler(event:MouseEvent):void
                  { trace("breakpoint");    }


              <s:HTTPService id="srv" url="data.xml"
          <s:Button click="button1_clickHandler(event)"/>



      The HTTPService gives me nothing; no error event, no success event, no invoke. When I freeze the program and look at the "srv", it doesn't seem to contain anything useful, like anything to take data from.


      The data.xml is both at the src-folder and its parent folder, and it looks like this:


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


      Why doesn't this work?

        • 1. Re: Cant open a simple XML file.
          EdAlive Level 1

          I've never used HTTPService to load xml.

          Here's how I've been doing it, if it helps.


          protected function init():void


               var loader:URLLoader = new URLLoader();

               loader.addEventListener(Event.COMPLETE, loader_completehandler);

               loader.load(new URLRequest('http://www.test.com/test.xml'));   // or relative url path


          protected function loader_completehandler(e:Event):void


               var xml:XML = new XML((e.target as URLLoader).data);


          1 person found this helpful
          • 2. Re: Cant open a simple XML file.
            Nuwan,Chamara Level 1



            I can't see in your code that you are using srv.send().


            Try calling srv.send() at the creation complete event handler to load the xml.

            • 3. Re: Cant open a simple XML file.
              jexer Level 1

              Thanks Nuwan


              It was missing the .send() command.


              I made the code after an example in TourDeFlex, and just couldn't spot the .send() that was in there. I've encountered so many bugs and inconsistent things in Flex that I just thought this is another bug or something.


              Thanks Edwan, too. I used to use the URLLoader but the HTTPService shrinks the 5 lines to one so I thought I'd figure that one out.