0

I allreday read a lot of helpful stuff in that forum. Now it's my first time I ask for specific help.

I'm pretty new to Flash and have a problem I struggle for more then a week now. The most efficient and elegant way for my problem is to put a StageWebView-Call into an as-File.

That would be the plan: In my flash-File: Show a PDF document "xyz" and put it on the stage.

I alreday tried it with Switch-Case - But then I have trouble to get rid of the PDF's.

That was my Idea: First the new 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);
        }

    }

}

Than I want to call that in my flash-File...

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

Two erros are shown:

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

With a lot more work I could avoid the first error by defining a lot of different as-Scripts for each pdf. My main problem is the second error.

It would be really nice if someone had any good ideas.

Bye, Stephan

2 Answers2

0

The second error means that you need to pass the stage to the web view. Either pass it to mypdf class as parameter, or make mypdf DisplayObject (extend Sprite for example) and add it to stage.

I'm not sure this will solve your issue anyways - I think StageWebView can simply display html. The PDF is displayed in your browser because an external plugin for that is launched.

In AIR the situation seems different: http://sujitreddyg.wordpress.com/2008/01/04/rendering-pdf-content-in-adobe-air-application/

Andrey Popov
  • 7,362
  • 4
  • 38
  • 58
0

StageWebView is wont support for nativePath, instead of using this, you can try with pdf.url. And StageWebView also having support for open .pdf files.

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

Because, StageWebView will support file:/// format, but in nativePath we got C://.., so, this will help you. Or Simply convert your StageWebView to Display object, and then added it to your container by using addElement().

You can convert it by,

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

To test by, simply call this method in added_to_stage method to test if stage is having or not. This error will come if stage is not setted means also.