• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

how to embed pdf file in flash based android application

Explorer ,
Dec 17, 2012 Dec 17, 2012

Copy link to clipboard

Copied

Im trying to create android and iPad application using the flash CS 5. Facing some problem to open the PDF file using some button inside my application.

I have PDF file and I want, when I press some button then PDF file will open. I'm using this code

myPDF.addEventListener(MouseEvent.CLICK, ldr);

    function ldr(event:MouseEvent):void {       navigateToURL(new URLRequest("Dimensions.pdf"), "_blank"); }

this code is working properly in the computer but in android tablet I got this error message **“ERROR, the ducoment path is not valid”**

Note: (my flash file (application file) and PDF file is in the same folder in my computer)

Please suggest me how I can open the PDF file using the button inside of my application.

TOPICS
ActionScript

Views

12.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 03, 2013 Jan 03, 2013

for your button to work when pressed, you should use:

public class bpdf extends SimpleButton

                    {

                               public function bpdf()

                              {

                              // constructor code

                                       this.addEventListener(MouseEvent.MOUSE_DOWN,downF) ;  // import flash.events.MouseEvent

                              }

                                        private function downF(e:Event):void{

                   

...

Votes

Translate

Translate
Contributor ,
Dec 19, 2012 Dec 19, 2012

Copy link to clipboard

Copied

You can use HTMLLoader class for loading pdf in your applicaiton or File and FileStream classes opening pdf files. These classes are available in air

Regards

kiran

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 19, 2012 Dec 19, 2012

Copy link to clipboard

Copied

Im the new in AS3, can you plz give me the code

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 19, 2012 Dec 19, 2012

Copy link to clipboard

Copied

here is the code

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;

var htm:HTMLLoader= new HTMLLoader();

htm.load(new URLRequest("some.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");

 

          }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 19, 2012 Dec 19, 2012

Copy link to clipboard

Copied

Thx Dear.

I try but it’s not working. I’m sure I did some mistake. I do like this

______________________________________________________________

On button property

                Export for ActionScript  (Check)
                Export in frame 1

                Class:     pdfclass

______________________________________________________________

In pdfclass.ac file I put your code as it is (just change the pdf file name)

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;

var htm:HTMLLoader= new HTMLLoader();

htm.load(new URLRequest("some.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");

          }

Note: my Flash with all other files you can download to use this link

http://www.delta-adv.com/nav/PDF_Link.rar

please solve may problem

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 20, 2012 Dec 20, 2012

Copy link to clipboard

Copied

download your file from here

http://www.mediafire.com/?jhxlqy25safiy36

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 22, 2012 Dec 22, 2012

Copy link to clipboard

Copied

Thanks for your effort, but sorry to say it’s not working

When I publish the file I got this error

“the class’pdfclass’ must subclass ‘flash.display.SimpleButton’ since it is liked to a library symbol of that type.”

I attached snapshot

link - Error.jpg

__________________________________________________________________________

In button property we have class with the name of pdfclass but the base Class is empty. I try to put Base Class: flash.display.SimpleButton, and edit something in your code

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 pdfclass extends SimpleButton

      {

                  public function pdfclass()

                  {

                              // 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");

                  }

      }

}

When I publish this file. I didn’t get any compiler errors but in output I got this Error

[SWF] link2.swf - 2919 bytes after decompression

TypeError: Error #1009: Cannot access a property or method of a null object reference.

          at button()

          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()

Test Movie terminated.

I attached snapshot

link2 - Error.jpg

I publish this file in APK and check in my android tablet but nothing happen. Link is not working

Note: I try to publish with and without include my test.pdf file to using this option

Player: AIR for Android  - Setting
included files: test.pdf

u can download the file using this link

http://www.delta-adv.com/nav/Link_2.rar

Any suggestion??

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 25, 2012 Dec 25, 2012

Copy link to clipboard

Copied

what's line 30 of button.as?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 25, 2012 Dec 25, 2012

Copy link to clipboard

Copied

This is my external class file name (button.as)

You can download my files using this link

http://www.delta-adv.com/nav/Link_2.rar

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 25, 2012 Dec 25, 2012

Copy link to clipboard

Copied

no thanks.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 25, 2012 Dec 25, 2012

Copy link to clipboard

Copied

do you have any solution for this?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 25, 2012 Dec 25, 2012

Copy link to clipboard

Copied

you either have to follow my suggestions/instructions or find someone who will follow your instructions.  ie, i don't download and correct problems unless i'm hired. 

however, someone else may do this for you if you are patient.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 25, 2012 Dec 25, 2012

Copy link to clipboard

Copied

Ok boss, Don’t download my files but please tell me if u have any suggestion regarding this

I create one button, on button property I use class (bpdf) and this is the code which I use

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

                        }

            }

}

When I publish my file with FLASH PLAYER 10.2, I got these compiler errors

Type was not found or was not compile-time constant: HTMLLoader.

Type was not found or was not compile-time constant: NAtiveWindowInitOptions.

Type was not found or was not compile-time constant: NativeWindow.

Call to possibly undefined method HTMLLoader.

Call to possibly undefined method NativeWindowInitOptions.

Access of undefined property NativeWindowSystemChrome.

Access of undefined property NativeWindowType.

Call to possibly undefined method NativeWindow.

Definition flash.html: HTMLLoader could not be found.

Definition flash.disply: NativeWindowInitOptions could not be found.

Definition flash.disply: NativeWindowSystemChrome could not be found.

Definition flash.disply: NativeWindowType could not be found.

Definition flash.disply: NativeWindow could not be found.

01.jpg

And when I publish my file with “PLYER: AIR FOR ANDROID” then I got these error message in output

[SWF] link2.swf - 2907 bytes after decompression

TypeError: Error #1009: Cannot access a property or method of a null object reference.

            at bpdf()

            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()

Test Movie terminated.

02.jpg

After polishing when I click on my button, nothing happened. Also convert my file in APK and check this file in my android device but same problem when I click on the button, nothing happened

I make my APK file without include pdf and with include pdf

Include my pdf file using this way

     Publish setting
          PLAYER: AIR FOR ANDROID – setting

               Included files: test.pdf

03.jpg

Note: in short I’m making IOS and Android base application in flash CS5.5.  I have one pdf file, want to open this pdf file when I press some button (in Ipad and Android device)

Plz give me the solution

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 25, 2012 Dec 25, 2012

Copy link to clipboard

Copied

the first problem (with the types not found errors) is caused by your publish settings:  you're using classes that are only available when publishing for air, not flash player 10.2.

the 2nd and 3rd problem list a problem on line 30 of bpdf.as.  what line is that?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 25, 2012 Dec 25, 2012

Copy link to clipboard

Copied

bpdf.as is my class file

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 26, 2012 Dec 26, 2012

Copy link to clipboard

Copied

i know that. 

what is line 30 of your bpdf class file?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 26, 2012 Dec 26, 2012

Copy link to clipboard

Copied

in bpdf class file in line number 30 my code is

win.stage.addChild(htm);

05.jpg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 27, 2012 Dec 27, 2012

Copy link to clipboard

Copied

the code in your constructor should not be executed until your button is added to the stage:

replace the code in your constructor with:

this.addEventListener(Event.ADDED_TO_STAGE,initF);

then add to your bpdf class:

private function initF(e:Event):void{

// the code that was in your constructor

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 29, 2012 Dec 29, 2012

Copy link to clipboard

Copied

I try something like this but I got error

01.jpg

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;

          this.addEventListener(Event.ADDED_TO_STAGE,initF);

 

          private function initF(e:Event):void{

 

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

                              }

 

                    }

          }

}

02.jpg

after that i try this, but got again error

03.jpg

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;

          this.addEventListener(Event.ADDED_TO_STAGE,initF);

 

          public class bpdf extends SimpleButton

                    {

                              private function initF(e:Event):void{

 

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

                              }

 

                    }

          }

}

04.jpg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 29, 2012 Dec 29, 2012

Copy link to clipboard

Copied

you didn't add that listener to your constructor and you're nesting methods.  use:

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


this.addEventListener(Event.ADDED_TO_STAGE,initF);

                              }

                              private function initF(e:Event):void{

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

                              }

                   

          }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 29, 2012 Dec 29, 2012

Copy link to clipboard

Copied

I got this output error

[SWF] link4.swf - 3031 bytes after decompression

TypeError: Error #1009: Cannot access a property or method of a null object reference.

      at bpdf/initF()

      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()

[UnloadSWF] link4.swf

Test Movie terminated.

01.jpg

i use same code which you give me

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

                                        this.addEventListener(Event.ADDED_TO_STAGE,initF);

                              }

                                         private function initF(e:Event):void{

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

                                                            }

                              }

}

02.jpg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 29, 2012 Dec 29, 2012

Copy link to clipboard

Copied

win needs to be added to the display list.  what do you want to parent it to?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 30, 2012 Dec 30, 2012

Copy link to clipboard

Copied

Sorry I didn’t understand, what do you mean….

I just want to open pdf file (when I publish flash file in Android or IOS)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 30, 2012 Dec 30, 2012

Copy link to clipboard

Copied

then you don't understand your code and that error message.

see if this does what you want:

public class bpdf extends SimpleButton

                    {

                               public function bpdf()

                              {

                              // constructor code

                                        this.addEventListener(Event.ADDED_TO_STAGE,initF) ;

                              }

                                         private function initF(e:Event):void{

                                                  var htm:HTMLLoader= new HTMLLoader();

                                                  htm.load(new URLRequest("test.pdf"));

this.parent.addChild(htm);

                                                  htm.width = win.width;

                                                  htm.height = win.height;

                                                  // create a close button for htm and add it (to this.parent) and its listener here

                                                  }

                                                            function onCloseEvent(e:Event)

                                                            {

                                                                      trace("window closed");

                                                            }

                              }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 30, 2012 Dec 30, 2012

Copy link to clipboard

Copied

Unfortunately, yes.

i dont understand this code. i just start AS3


This time I got this error

01.jpg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines