如何在基于Flash的应用程序中嵌入pdf文件(IOS和android)

时间:2012-12-27 09:28:11

标签: actionscript-3 flash flash-cs5

我正在使用FLASH CS5.5为Android和IOS创建应用程序

我想在点击按钮时打开pdf文件。我尝试使用此代码,但无法正常工作

package
{
            import flash.html.HTMLLoader;
            import flash.net.URLRequest;
            import flash.display.NativeWindowInitOptions;
            import flash.display.NativeWindowSystemChrome;
            import flash.display.NativeWindowType;
            import flash.display.NativeWindow;
            import flash.events.Event;

            import flash.display.SimpleButton;


            public class bpdf extends SimpleButton
            {

                        public function bpdf()
                        {
                                    // constructor code
                                    var htm:HTMLLoader= new HTMLLoader();
                                    htm.load(new URLRequest("test.pdf"));
                                    var init:NativeWindowInitOptions= new NativeWindowInitOptions();
                                    init.systemChrome = NativeWindowSystemChrome.STANDARD;
                                    init.type = NativeWindowType.NORMAL;
                                    var win:NativeWindow = new NativeWindow(init);
                                    win.stage.addChild(htm);
                                    win.width = stage.stageWidth;
                                    win.height = stage.stageHeight;


                                    win.activate();
                                    htm.width = win.width;
                                    htm.height = win.height;
                                    win.addEventListener(Event.CLOSE, onCloseEvent);
                        }

                        function onCloseEvent(e:Event)
                        {

                                    trace("window closed");

                        }
            }
}

使用“PLYER:AIR FOR ANDROID”发布后,我在输出中收到了这些错误消息

[SWF] link2.swf - 2907 bytes after decompression
TypeError: Error #1009: Cannot access a property or method of a null object reference.
            at bpdf()[C:\Users\HP\Desktop\PDF Link\Link_2\bpdf.as:30]
            at flash.display::Sprite/constructChildren()
            at flash.display::Sprite()
            at flash.display::MovieClip()
            at runtime::ContentPlayer/loadInitialContent()
            at runtime::ContentPlayer/playRawContent()
            at runtime::ContentPlayer/playContent()
            at runtime::AppRunner/run()
            at ADLAppEntry/run()
            at global/runtime::ADLEntry()

我还在APK中转换我的文件并检查我的Android设备但是当我点击按钮时出现同样的问题,没有发生任何事情

我制作的APK文件没有包含pdf和包含pdf

使用这种方式包含我的pdf文件::发布设置> PLAYER:AIR FOR ANDROID - 设置>包含的文件:test.pdf

1 个答案:

答案 0 :(得分:0)

试试这个

如果要打开pdf,请使用StageWebView而不是HTMLLoader类。喜欢这个

protected function loadPDF(event:MouseEvent):void { 

var file:String = "Lorem_Ipsum.pdf";  

var yOffset:Number = 40;  

var stageWebView:StageWebView = new StageWebView(); 

stageWebView.stage = stage;  
stageWebView.viewPort = new Rectangle(0, yOffset, 500, 500 - yOffset); 

 var pdf:File = File.applicationStorageDirectory.resolvePath(file);  

stageWebView.loadURL(pdf.nativePath);
}

来源:more details

另请参阅stack overflow display-local-pdf