Open PDF in PDF Reader from AIR Desktop Application - actionscript-3

I'been trying to open a pdf document from inside of an Adobe Air Desktop application created with Adobe Flash CS 6.
I Used this code:
import flash.filesystem.*;
var thePDF = "mypdf.pdf";
var realFile:File = File.applicationDirectory.resolvePath(thePDF);
var destination:File = File.documentsDirectory;
destination = destination.resolvePath(thePDF);
realFile.copyTo(destination,true);
destination.openWithDefaultApplication();
This works fine when I am testing inside Flash CS6, but stops to work when I publish the application in an .exe file (Same case in MACOS with .app file).
I tryied with all the resources I found in google, nothing works!!!
Actualy I found a code from a AS3 library called Shu (com.cjt.Shu) but there is no any documentation recorded in the web.
If any body knows about this Shu or some other alternative even no Open Source. Please let me know.
Thank you all in advance, regards from México.

Are you sure that your PDF content is in the folder of the actual published AIR?
It looks like the PDF is out of scope.
EDIT: Here´s some code to explain a bit more:
file1.addEventListener(MouseEvent.CLICK, pdf1, false, 0, true);
function pdf1(e:MouseEvent):void{
navigateToURL(new URLRequest(File.applicationDirectory.nativePath + "/files/My_PDF_File.pdf" ));
}
Double check the route of your target file. In my case, it is in the local folder of my published AIR folder in the "files" folder.
Hope this can help you.

Related

SWFLoader Working in Air Project but not Web Project

I have been developing a Web type Flex project in Flash builder. In this project I have been trying to load a swf file using the SWFLoader. I have had trouble getting the debugger working, so I have instead created an identical Air project that I can run and debug with (I keep it up to date with a script). I have successfully loaded the swf file in my Air project with no trouble. But, when I went to test this in my Web project, the SWFLoader does not seem to work, I just get a blank area where my SWFLoader element should display the loaded swf file.
private function get_swf_file_binary_amf(event:ResultEvent):void {
Alert.show("SWF Returned");
var decoder:Base64Decoder=new Base64Decoder();
decoder.decode(event.result);
var swf_bytes:ByteArray=decoder.toByteArray();
var context:LoaderContext=new LoaderContext();
context.allowLoadBytesCodeExecution=true;
context.parameters = {myval: "test_string"};
swf_loaded_file.loaderContext = context;
swf_loaded_file.addEventListener(Event.COMPLETE, loadComplete);
swf_loaded_file.load(swf_bytes);
}
private function loadComplete(completeEvent:Event):void{
trace("load Complete")
}
Above is the code that works in my Adobe Air project. I am receiving the binary data of my swf file and converting it into a ByteArray, not using the URLLoader like so many example suggest. Could this be the cause of my problems when I try to run this in my Web project?
Edit/Update: I have found the particular line where the Web project fails:
context.allowLoadBytesCodeExecution=true;
I am still not sure why my Web project does not like this line, yet my Air project doesn't care.
I have removed the accursed line:
context.allowLoadBytesCodeExecution=true;
This seems to have fixed the problem. I am not even quite sure what this line does, I had just carried it over from a tutorial. Getting rid of it didn't seem to break anything that worked in my Air project, so I think that solved my problem.

How can I open PDF files inside a Mac node-webkit application?

I'm trying to add support for PDFs in my Mac node-webkit app. I tried using "PDF.js" but it requires the use of a web server so this won't help me.
I've already solved this issue for the PC version of the node-webkit app by installing "Adobe Acrobat Reader" and adding the "nppdf32.dll" file inside the plugins folder of the root directory of the PC application.
Now I'm trying to solve this issue for the Mac version. How can I open PDF files inside my Mac node-webkit application?
If you still want to try PDF.js, this is how I have gotten it working.
After downloading all the files, the main ones that do all the work are viewer.html and viewer.js. You can point to viewer.html from anywhere in your node-webkit app by doing something like:
$(".some-pdf").on("click", function(){
window.location.href = "path-to-pdfjs/viewer.html";
});
To determine which file it opens, there's a variable in view.js.
var DEFAULT_URL = 'pdfs/something.pdf';
Since you're using node-webkit, it won't have any issues accessing the file system.
I made it a little more dynamic, where the link can point to any specific pdf, by doing the following. In any file, the link adds a hash with the file name:
$(".some-pdf").on("click", function(){
window.location.href = "path-to-pdfjs/viewer.html#specific.pdf";
});
Then in viewer.js:
var DEFAULT_URL = 'pdfs/' + window.location.hash.replace("#", "");
Then it is a bit reusable through your app, if there are multiple pdf files involved.

How to load swf created with flipbook maker into flash

I'm trying to load the swf created by 'flip book maker' into my project.
the files created by flipbook maker are
book.swf
framework.swf
I used the following code
var myLoader:Loader = new Loader();
var url:URLRequest = new URLRequest("book.swf");
myLoader.load(url);
addChild(myLoader);``
the framework.swf is linked with book.swf, so it cannot run alone.
When I run the movie it shows the Error #2032, Stream error to framework.swf
book.swf and framework.swf both are in the same directory.They are generated by flip book maker What I needed is to load the book.swf into my project at a particular frame. I need help in AS3 for this purpose.
How to fix it..?
please help me..!
Error #2032 means that your Flash application could not load the framework.swf for some reason (you know this already of course). What you need to find out is why. Possible reasons are: you have the wrong URL, the framework.swf is not in the place you expect, there are crossdomain restrictions on the file you are trying to access ( you did not state where frameworks.swf).
What I would suggest doing is using a web debugging proxy tool like Fiddler (http://www.telerik.com/fiddler) or Firebug (is a Firefox extension) and take a look at the http requests to get more information on your error. You may find out that frameworks.swf is not in the location you expect.
This is just a IOError event triggered by Adobe Flash. Most likely the file just isn't found. Check your path and make sure you place the .swf file in your bin-debug directory if you're doing this from within Adobe Flash Builder

xml in flash actionscript couldn't loaded due to wordpress permalinks

i'm new bee in flash actionscript. i want to load xml file to show some text. I used to embed flash object in wordpress. i create a newfolder in root of wordpress like wordpress/flash. xml files are exist in flash folder. i want to load those xml files on runtime in action script. i'm using this code
var xml_loader:URLLoader = new URLLoader();
xml_loader.load( new URLRequest("http://www.example.com/flash/page_1.xml"));
but it's not working at live, i run .swf file locally it's done well and load data from live site but as i upload it to the live server and try to use it there it's stuck to loading...
please help me on this issue
thanks
Try adding a cross-domain policy file at the root of your site:
http://kb2.adobe.com/cps/142/tn_14213.html
Also, having a browser tracer for debugging is quite helpful when developing:
https://addons.mozilla.org/en-US/firefox/addon/flashtracer/ (add-on)
Lastly, check if any error is being dump in the browser console:
Chrome: View -> Developer -> Developer Tools
Firefox: Tools -> Web Developer -> Firebug (add-on)
You need to use "base" attribute to embed XML driven swf in wordpress.. Here is the solution http://masterblogster.com/how-to-embed-swf-file-in-wordpress-that-loads-xml-file/

Creating an external .txt in as3

how do I automatically create an external .txt file without asking the user for directory. I am using the following code so as to create and save the ".txt "file, but my code asks for the directory to save the file. I want the file to be saved automatically without asking user for the directory...
import flash.net.FileReference;
import flash.events.Event;
addEventListener(Event.ENTER_FRAME,saveFile);
var ss:String = "this is text to write";
var fileRef:FileReference;
function saveFile(event:Event):void
{
fileRef=new FileReference();
fileRef.save(ss,"save.txt");
removeEventListener(Event.ENTER_FRAME, saveFile);
}
Are you creating an AIR appplication for desktop? If so, you can use File and FileStream.
var f:File=new File("path\to\file.txt");
var str:FileStream=new FileStream();
str.open(f, FileMode.WRITE);
str.writeUTFBytes(contents);
str.close();
If you are creating a flash-player application, then you must ask the user for a path to save (because an online app saving without a user's knowledge is just WRONG)
You cannot do that for security reasons if it's a browser app... Maybe you can try using SharedObjects instead...
is definitely a security issue - saving files without the user knowing what you're doing just isn't right. AIR is the exception - as a "normal" appliaction it can save a file without asking where to put it.
If you are running in a browser, you CAN save to a file, you have to use external interface and be on file:/// protocol and use something like jQuery.twFile.js
Can be done if you compile to AIR (Desktop app). But cannot be done with browser. As i think, it will go against browser's security. Just think, if it were possible, then websites would start storing and loading content on your system without your permission. :)