2014-03-25 57 views
0

我allreday閱讀了很多有用的東西在該論壇。現在這是我第一次請求具體幫助。StageWebView在AS3腳本

我對Flash非常陌生,並且遇到了一個問題,現在我已經爭取了一個多星期。對於我的問題,最有效和最優雅的方法是將StageWebView-Call放入as-File中。

這將是計劃: 在我的flash文件中:顯示PDF文檔「xyz」並將其放在舞臺上。

我alreday用Switch-Case試過它 - 但後來我無法擺脫PDF的。

這是我的想法: 一是新作 - 文件...

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的腳本。 我的主要問題是第二個錯誤。

如果有人有任何好主意,這將是非常好的。

再見, 斯蒂芬

回答

0

第二個錯誤意味着你需要在舞臺傳遞到Web視圖。將它作爲參數傳遞給mypdf類,或者使mypdf DisplayObject(例如擴展Sprite)並將其添加到舞臺。

我不知道這會解決您的問題 - 我認爲StageWebView可以簡單地顯示HTML。 PDF將顯示在您的瀏覽器中,因爲已啓動該插件的外部插件。

在空氣中的情況似乎有所不同:http://sujitreddyg.wordpress.com/2008/01/04/rendering-pdf-content-in-adobe-air-application/

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中支持文件:///格式,但在我們的nativePath了C:// ..,所以,這將幫助你。或者 只需將StageWebView轉換爲Display對象,然後使用addElement()將其添加到容器中即可。

你可以把它轉換,

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

爲了測試,只需調用此方法ADDED_TO_STAGE方法,可測試階段是有或沒有。如果舞臺沒有設置,也會出現這個錯誤。