Copy link to clipboard
Copied
Want to open PDF file inside the application. I try this code, its working in the PC but when I publish this, as an APK file it’s not working in my android device
package {
import flash.display.SimpleButton;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.html.HTMLLoader;
import flash.net.URLRequest;
public class bpdf extends SimpleButton {
public function bpdf() {
// constructor code
this.addEventListener(MouseEvent.MOUSE_DOWN,downF) ;
}
private function downF(e:Event):void {
var htm:HTMLLoader= new HTMLLoader();
htm.load(new URLRequest("test.pdf"));
htm.width=200;
htm.height=300;
htm.x=50;
htm.y=20;
this.parent.addChild(htm);
// create a close button for htm and add it (to this.parent) and its listener here
}
function onCloseEvent(e:Event) {
if(!HTMLLoader.isSupported){
this.alpha=.1;
}
}
}
}
1 Correct answer
use:
import flash.media.StageWebView;
import flash.geom.Rectangle;
import flash.desktop.NativeApplication;
import flash.events.MouseEvent;
import flash.filesystem.File;
var swv: StageWebView = new StageWebView();
swv.viewPort = new Rectangle(0, 0, 500, 250); // 500px width, 450px height
swv.stage = this.stage; // set stage of StageWebView to document class
var templateFile:File = File.applicationDirectory.resolvePath("test.pdf" );
var workingFile:File = File.createTempFile();
templateFile.copyTo(workingFil
...Copy link to clipboard
Copied
use stagewebview instead of htmlloader.
Copy link to clipboard
Copied
I try StageWebView
package {
import flash.display.SimpleButton;
import flash.media.StageWebView;
import flash.geom.Rectangle;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.desktop.NativeApplication;
import flash.events.MouseEvent;
public class bpdf extends SimpleButton {
private var webView:StageWebView = new StageWebView();
public function bpdf() {
this.addEventListener(MouseEvent.CLICK,clickF);
}
public function clickF(e:MouseEvent):void {
var swv:StageWebView = new StageWebView();
swv.viewPort = new Rectangle(0,0,500,250); // 500px width, 450px height
swv.stage = this.stage; // set stage of StageWebView to document class
swv.loadURL("test.pdf"); // load any content
stage.addEventListener( KeyboardEvent.KEY_DOWN, onKey );
}
private function onKey( event:KeyboardEvent ):void {
if( event.keyCode == Keyboard.BACK && webView.isHistoryBackEnabled ) {
trace("Back.");
webView.historyBack();
event.preventDefault();
}
if( event.keyCode == Keyboard.SEARCH && webView.isHistoryForwardEnabled ) {
trace("Forward.");
webView.historyForward();
}
}
}
}
but got this error
Copy link to clipboard
Copied
your pdf must be added to your include files list in the android publish settings. your pdf needs to be in the same directory as your published files when you specify no path.
also, add error listeners.
Copy link to clipboard
Copied
I already include my pdf file in my android publish setting
Copy link to clipboard
Copied
i don't know if this will help, but change your publish settings to publish your apk to the same directory as your swf.
Copy link to clipboard
Copied
i try but when i check in my android device i got this
Copy link to clipboard
Copied
use:
import flash.media.StageWebView;
import flash.geom.Rectangle;
import flash.desktop.NativeApplication;
import flash.events.MouseEvent;
import flash.filesystem.File;
var swv: StageWebView = new StageWebView();
swv.viewPort = new Rectangle(0, 0, 500, 250); // 500px width, 450px height
swv.stage = this.stage; // set stage of StageWebView to document class
var templateFile:File = File.applicationDirectory.resolvePath("test.pdf" );
var workingFile:File = File.createTempFile();
templateFile.copyTo(workingFile, true );
try{
swv.loadURL( workingFile.url );
} catch (e:Error){
trace( e );
}
Copy link to clipboard
Copied
Thx for reply boss. In this time no error but when I publish in my PC, on that time I got white screen
but when I open this file in android device, after 1 to 2 mint I got this screen (my pdf file size is only 74 KB)
Here is my publish setting which I use
Copy link to clipboard
Copied
that code works for me so i'm not sure what you're doing wrong. you might check with another pdf to make sure it's not a pdf problem. otherwise, someone will probably need to download and correct your files.
Copy link to clipboard
Copied
I try to change my PDF file but facing the same problem
Do i have to install any plugin for this?
Can you send me your file which you made? (Which AIR SDK you are using?)
Copy link to clipboard
Copied
this works with air for android 3.6 and 3.8. i didn't test anything else: http://www.kglad.com/Files/forums/testPDFload.fla
Copy link to clipboard
Copied
thx boss. It’s working in the PC but when I check this in the Android device its look like crash.
I try to change my pdf file as wll but facing the same problem. Any idea what is the problem?
Copy link to clipboard
Copied
you need a pdf reader on your android device. check gdocs.
Copy link to clipboard
Copied
I installed this
https://play.google.com/store/apps/details?id=art.wild.gdocs&hl=en
https://play.google.com/store/apps/details?id=com.rcs.mydocs&hl=en
but facing the same problem
In my android device I already have adobe reader

