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.
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{
...
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
Copy link to clipboard
Copied
Im the new in AS3, can you plz give me the code
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");
}
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
Copy link to clipboard
Copied
download your file from here
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
__________________________________________________________________________
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
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??
Copy link to clipboard
Copied
what's line 30 of button.as?
Copy link to clipboard
Copied
This is my external class file name (button.as)
You can download my files using this link
Copy link to clipboard
Copied
no thanks.
Copy link to clipboard
Copied
do you have any solution for this?
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.
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.
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.
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
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
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?
Copy link to clipboard
Copied
bpdf.as is my class file
Copy link to clipboard
Copied
i know that.
what is line 30 of your bpdf class file?
Copy link to clipboard
Copied
in bpdf class file in line number 30 my code is
win.stage.addChild(htm);
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
}
Copy link to clipboard
Copied
I try something like this but I got error
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");
}
}
}
}
after that i try this, but got again error
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");
}
}
}
}
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");
}
}
}
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.
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");
}
}
}
Copy link to clipboard
Copied
win needs to be added to the display list. what do you want to parent it to?
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)
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");
}
}
Copy link to clipboard
Copied
Unfortunately, yes.
i dont understand this code. i just start AS3
This time I got this error