简体   繁体   English

如何在Flex ActionScript 3中读取XML文件

[英]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. 我想读取放置在与swf相同的文件夹中的xml文件。 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(); 因此,在CreationComplete事件上,我调用startup();。 The Checkpoint1 output displays but none of the other checkpoints are reached? 显示Checkpoint1输出,但没有到达其他检查点?

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! 谁能告诉我我做错了什么或者更好的事,但是告诉我如何读取与swf文件位于同一文件夹中的文件!

Thanks 谢谢

Not sure why it's not reaching the second checkpoint... If you comment out loader = new URLLoader(my_req); 不知道为什么它没有达到第二个检查点...如果您注释掉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). 如果要在Flex中加载本地文件,有时必须设置use-network=false编译器参数(将其设置为false,默认为true)。 Here's some info on use-network and security sandboxes . 以下是有关use-network和安全沙箱的信息

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. 在这种情况下-您应该使用Adobe Air而不是Flex-它将对您很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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