0

我正在使用 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 文件:: 发布设置 > 播放器:AIR FOR ANDROID – 设置 > 包含的文件:test.pdf

4

1 回答 1

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);
}

来源:更多细节

另请查看堆栈溢出 display-local-pdf

于 2012-12-27T12:01:53.453 回答