Flash Builder URL local path not allowed

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

My code is as follows:

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 much "../" I paste into the URLRequest constructor, it only works if NPClist.xml is in the same folder as .swf (bin-debug), and I even tried to copy it. It appears to be ignoring / not allowing "../". I also tried to export the release build, but that didn't work. Interestingly, Embeds works the same way (the resource 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); 

"../" did not work initially, but it works if you use it like that.


Returning to this, this also seems wrong. Here, how it definitely works, as expected:

I have included assets with the installer and I use

 imgFile=File.applicationDirectory.resolvePath("assets/folder/file"); urlReq=new URLRequest(imgFile.nativePath); ldr.load(urlReq); 
+4
source share
2 answers

You cannot use URLRequest to access local file system resources. URLRequest uses the HTTP protocol to receive resources.

URLRequest can only access Internet resources that are protected against cross-access.

If you want to open a local file, you must:

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

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

-3
source

You must store your local assets in the html-template folder, then it will load your assets using IOError for the web application, otherwise use the file: /// to load local assets in case of an AIR application

0
source

Source: https://habr.com/ru/post/1436877/


All Articles