开发者

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(Ev开发者_StackOverflow社区ent.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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜