Question

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);
Was it helpful?

Solution

You can not use URLRequest to access local file system resources - URLRequest uses HTTP protocol to get resources.

URLRequest can access only Internet resources that have crossdomain security applied.

If you want to open a local file you should:

  • either explicitly force the user to open the file use Open File Dialog (http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html)

  • or use AIR runtime (with AIR you can open local files, but not with URLRequest but with File class).

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top