Flash Builder URLRequest local path not resolving

manabk picture manabk · Sep 28, 2012 · Viewed 8.3k times · Source

This is my basic folder structure: http://i.stack.imgur.com/l1YnV.jpg

My code goes like this:

private var xmlLoader:URLLoader=new URLLoader();
private var url:URLRequest=new URLRequest("../src/NPClist.xml");

xmlLoader.load(url);

I get the following:

Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: app:/src/NPClist.xml

No matter how many "../" I put in the URLRequest constructor, it only works if NPClist.xml is in the same folder as the .swf (bin-debug), and I even tried copying it around. It seems like it's ignoring/not resolving the "../". I also tried exporting a release build, but it didn't work. The interesting thing is that similar Embeds work (the assets folder is at the same level as src and bin-debug).

[Embed(source="assets/mainmenu/somefile.png")]

Here's how I got it to work:

var xmlFile:File=new File(File.applicationDirectory.nativePath).resolvePath("../src/NPClist.xml");
var url:URLRequest=new URLRequest(xmlFile.url);

The "../" didn't work initially, but it works if you use it like this.


Coming back to it, this seems wrong as well. Here's how it definitely works as expected:

I included the assets with the installer, and I'm using

imgFile=File.applicationDirectory.resolvePath("assets/folder/file");
urlReq=new URLRequest(imgFile.nativePath);
ldr.load(urlReq);

Answer

Anjul picture Anjul · Sep 20, 2014

You have to keep your local assets inside html-template folder then it'll load your assets with out IOError for Web application otherwise use file:/// to load local assets in case of AIR application