Copy link to clipboard
Copied
I had a lot of trouble getting this to work, and I'm hoping this post saves someone time. Some of the information that's been posted in other locations is either wrong, incomplete, or might only work on Android. By the time you read this message the information here may no longer be accurate, so here's the testing environment:
Window 7
Flash CS 5.5.0
AIR 2.7.0.19530, which was compiled on June 28, 2011
iPad 1, version 4.3.5 of iOS
Let's get started.
Here's some code I've successfully tested several times on both iOS and Windows. The file is copied to the temp directory. The file's extension is restored by just slapping the original file name to the end of the temp file.
private function loadExternalFile():void
{
var webView = new StageWebView();
webView.stage = this.stage;
webView.viewPort = new Rectangle( 0, 0, 1024, 555 );
// Works with either html or pdf files.
// These are stored in the root of the application directory.
var fileName:String = "euei.pdf";
//var fileName:String = "euei.htm";
var sourceFile = File.applicationDirectory.resolvePath( fileName );
var workingFile = File.createTempFile();
try
{
sourceFile.copyTo( workingFile, true );
// You have to rename the temp file
var renamedTempFile:File = workingFile.resolvePath(workingFile.nativePath + fileName);
workingFile.moveTo(renamedTempFile, true);
webView.loadURL( renamedTempFile.url );
}
catch (err:Error) { }
}
Copy link to clipboard
Copied
Thank you very much...
Works with CS6 and AIR 3.3 SDK too
Oli
Copy link to clipboard
Copied
Thank you very much!
Copy link to clipboard
Copied
I tried this with Flash CS5.5 and AIR 4.0 SDK. Any pdf loaded simply fills the viewPort with black. Also tested with a png version of the pdf and that displayed just fine.
What's the purpose of copying to a temp work file? I found that webView.loadURL( sourceFile.url ); gave me the exact same results.
Any ideas?
Thanks!