I am trying to load local HTML (that exists in the project's folder structure) in an instance of webStageView. While this works fine in windows and ipad/iphone - it fails to locate the files in Android (only tried it in 2.2)
File.applicationDirectory.url returns "app:" File.applicationStorageDirectory.url returns "app-storage:"
File.applicationDirectory.nativePath returns an empty string, as specified in Adobe's documentation.
The problem is that the webview gives a "Web page not available, app:/test/index.html not found" error. Is there a way to get the full path, or to "force" the browser to understand that app: refers to a specific folder?
Than开发者_StackOverflow社区ks!
As Adobe help states:
The app: and app-storage: schemes are not supported.
On iOS your code works perfectly, but on Android, you have to achieve it with some hacky implementation like yours, because security issues related to StateWebView loading urls from those directories. Another solution is to copy your app: or app-storage: file into a temporary one and load that temp file url into StageWebView:
var htmlFile:File = File.applicationDirectory.resolvePath(url);
var workingFile:File = File.createTempFile();
htmlFile.copyTo(workingFile, true);
stageWebView.loadURL(workingFile.url);
Edit: Another solution could be to have your html content coded into an .as file and use StageWebView.loadString() method. Having in mind that you have to encode that string for Android devices.
I fix this problem a couple of days a go. The file: URL scheme refers to a file on the client machine. There is no hostname in the file: scheme; you just provide the path of the file. So, the file on your local machine would be file:///~User/2ndFile.html. Notice the three slashes; the hostname part of the URL is empty, so the slash at the beginning of the path immediately follows the double slash at the beginning of the URL. You will also need to expand the user's path; ~ does no expand in a file: URL. So you would need file:///home/User/2ndFile.html (on most Unixes), file:///Users/User/2ndFile.html (on Mac OS X), or file:///C:/Users/User/2ndFile.html (on Windows). This solution work perfectly in my app.
精彩评论