Skip to content

Instantly share code, notes, and snippets.

@marchbold
Last active September 29, 2016 19:25
Show Gist options
  • Select an option

  • Save marchbold/8cce8b5804b520f23aba to your computer and use it in GitHub Desktop.

Select an option

Save marchbold/8cce8b5804b520f23aba to your computer and use it in GitHub Desktop.
Load a packaged file from a 'www' directory into a WebView
// Here we assume you have previously initialised the extension
var webView:WebView = NativeWebView.service.createWebView( new Rectangle( 0, 0, 400, 600 ) ) ;
var file:File;
var fileUrl:String;
if (NativeWebView.service.version.indexOf("Android") > 0)
{
// Android: Copy the application packaged files to an accessible location
var packagedWWWRoot:File = File.applicationDirectory.resolvePath( "www" );
var destination:File = File.applicationStorageDirectory.resolvePath( "www" );
packagedWWWRoot.copyTo( destination, true );
// Grab the file url
file = File.applicationStorageDirectory.resolvePath( "www/example.html" );
fileUrl = "file://"+file.nativePath;
}
else
{
// iOS:
file = File.applicationDirectory.resolvePath( "www/example.html" );
fileUrl = "file://"+file.nativePath;
}
webView.loadURL( fileUrl );
// com.distriqt.NativeWebView
@marchbold

Copy link
Copy Markdown
Author

@ZehCastro

Copy link
Copy Markdown

Line 7 has an error.
It should be NativeWebView.service.implementation instead of NativeWebView.service.version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment