views:

375

answers:

2

Hi,

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

A: 

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.

Shane C. Mason
hmm thanks, lemme look into air. Is there no way to do it from flex?
MAC
Air and Flex are really the same thing - just a difference in how you deploy them. Flex swf files are not meant for desktop deployment.
Shane C. Mason
+1  A: 

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

viatropos
Hmm the '-use-network=false' did not help but what it did do was get me past loader = new URLLoader(my_req);So now i get all the check points printed out.However the output.text+= XML(loader.data).string+"\n"; outputs a blank line. Which means what?I guess since its in the event.Complete that means the file was found and read? So now the question is why does it output a blank line.
MAC
Ha. Figured it out. output.text= XML(loader.data).string; The above line does not work.Replaced it with output.text=loader.data;and now i get the xml text!Thanks Man!
MAC