0

我在那个论坛上读了很多有用的东西。现在这是我第一次寻求具体帮助。

我对 Flash 还很陌生,现在有一个问题我已经挣扎了一个多星期。解决我的问题的最有效和最优雅的方法是将 StageWebView-Call 放入 as-File。

这将是计划: 在我的闪存文件中:显示 PDF 文档“xyz”并将其放在舞台上。

我已经尝试过使用 Switch-Case - 但是我很难摆脱 PDF。

那是我的想法:首先是新的 as-File ......

package  {

import flash.display.MovieClip;
import flash.media.StageWebView;
import flash.geom.Rectangle;
import flash.filesystem.File;
import flash.display.Sprite;
import flash.display.Stage;


    public class mypdf {
            public var MyWebView:StageWebView
            public var file:String
            public var pdf:File


        public function mypdf(ActFile:String) {
                MyWebView = new StageWebView();
                file = ActualFile;                         //MARKING #1
                pdf = File.applicationDirectory.resolvePath(file);

                MyWebView.stage = stage;                   //MARKING #2
                MyWebView.viewPort = new Rectangle (200, 200, 400, 400);            
                MyWebView.loadURL(pdf.nativePath);
        }

    }

}

比我想在我的闪存文件中调用它...

stop();
var mynewpdf:mypdf = new mypdf("test.pdf");

显示两个错误:

1120: Access of undefined property error ActualFile (at Marking #1)
1120: Access of undefined property error Stage (at Marking #2)

通过更多的工作,我可以通过为每个 pdf 定义许多不同的 as-Scripts 来避免第一个错误。我的主要问题是第二个错误。

如果有人有任何好主意,那就太好了。

再见,斯蒂芬

4

2 回答 2

0

第二个错误意味着您需要将阶段传递给 Web 视图。要么将其作为参数传递给 mypdf 类,要么制作 mypdf DisplayObject(例如扩展 Sprite)并将其添加到舞台。

我不确定这是否会解决您的问题 - 我认为 StageWebView 可以简单地显示 html。PDF 显示在您的浏览器中,因为为此启动了一个外部插件。

在 AIR 中,情况似乎有所不同:http ://sujitreddyg.wordpress.com/2008/01/04/rendering-pdf-content-in-adobe-air-application/

于 2014-03-25T15:47:28.413 回答
0

StageWebView 不支持 nativePath,您可以尝试使用 pdf.url,而不是使用它。而且 StageWebView 还支持打开的 .pdf 文件。

public function mypdf(ActFile:String) {
            MyWebView = new StageWebView();
            file = ActualFile;                         //MARKING #1
            pdf = File.applicationDirectory.resolvePath(file);

            MyWebView.stage = stage;                   //MARKING #2
            MyWebView.viewPort = new Rectangle (200, 200, 400, 400);    
            addChild( MyWebView );        
            MyWebView.loadURL(pdf.url);
    }

因为,StageWebView 将支持 file:/// 格式,但是在 nativePath 中我们得到了 C://..,所以,这将对您有所帮助。或者只需将 StageWebView 转换为 Display 对象,然后使用 addElement() 将其添加到容器中。

您可以通过以下方式转换它,

   var _view:SpriteVisualElement = new SpriteVisualElement();
   _view.addChild( MyWebView);
   this.addElement( view );

要进行测试,只需在 added_to_stage 方法中调用此方法即可测试 stage 是否有。如果未设置阶段,也会出现此错误。

于 2014-05-27T06:37:02.957 回答