简体   繁体   中英

How to read an xml file in flex actionscript 3

I want to read an xml file placed in the same folder as the swf. Note however there is no webserver running.

<![CDATA[               

            private var my_req:URLRequest = new URLRequest("assets/GmetadOutput.xml");
            private var loader:URLLoader;   

            public function startup():void {
            output.text="CheckPoint1"; //This is the only output that displays!
  loader = new URLLoader(my_req);
  output.text="CheckPoint2";
  loader.addEventListener(Event.COMPLETE,eventhandler);
  output.text="CheckPoint3";

  }

  public function eventhandler(ev:Event):void {
  output.text="CheckPoint4";
  output.text= XML(loader.data).string;
  }
        ]]>

So on the on CreationComplete event i call startup(); The Checkpoint1 output displays but none of the other checkpoints are reached?

Can anyone tell me what iam doing wrong or better yet tell me how to read a file placed in the same folder as the swf file!

Thanks

Not sure why it's not reaching the second checkpoint... If you comment out loader = new URLLoader(my_req); , does it work? If not, that's weird.

If you want to load local files in Flex, you sometimes have to set the use-network=false compiler argument (set it to false, it defaults to true). Here's some info on use-network and security sandboxes .

Let me know if that helps, Lance

When you say 'no webserver running' - I assume you saying that you are running it from a local file? In that case - you should use Adobe Air instead of just Flex - then it will work fine for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM