PDA

View Full Version : Adobe AIR :browseForOpen PDF docs


Faticus
06-02-2009, 09:10 AM
Hi,
I'm new to AIR and am trying to load PDF files into Flash CS3, which I've managed to do, if they are placed in the same folder as the app, but would like to select PDF's from elsewhere (other folders) and need to know how to include the relevant path. Also after the PDF has loaded and the Clip is resized I lose the PDF and just get a black screen!
Many Thanks in Advance!:eek:
Code below
import flash.display.Sprite;
import flash.html.*;
import flash.net.URLRequest;
import flash.filesystem.*;

function findPDF():void
{
var docFilter:FileFilter = new FileFilter("Documents", "*.pdf;*.doc");
var myFile:File = new File();
myFile.browseForOpen("Open", [docFilter]);
myFile.addEventListener(Event.SELECT, fileSelected);


}

function fileSelected(evt:Event)
{

loadPDF(evt.target.name);


}



function loadPDF(pdfTitle:String):void
{
var request:URLRequest = new URLRequest(pdfTitle);
var pdf:HTMLLoader = new HTMLLoader();

//set the dimensions
pdf.height = 640;
pdf.width = 900;

//call the load method
pdf.load(request);

//add the HTMLLoader object to the display list to make it visible
addChild(pdf);
}


findPDF();

Faticus
06-04-2009, 09:42 AM
Getting really frustrated with this now, so created a flex version, but still no joy!
Would really appreciate someones input on this.
I would like to know how to display a pdf file from my desktop into this AIR app (code below):
The app works if I place the pdf file within the src of the app, but not if the pdf is external(on my desktop).
Inputting this path into the text field /Users/foofoo/Desktop/somepdf.pdf (Mac)
does not work.....so what would?
What do I need to do?
Mucho Thanks in advance!
I'll post solution if I find it first, for all you other AIR newbie frustratees!

<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
height="720" width="700" horizontalAlign="left">
<mx:Script>
<![CDATA[
private function loadPDF(fileStuff:String):void
{

var request:URLRequest = new URLRequest(fileStuff);
var pdf:HTMLLoader = new HTMLLoader();

//set the dimensions
pdf.height = 630;
pdf.width = 660;

//call the load method
pdf.load(request);

//add the HTMLLoader object to the display list to make it visible
container.addChild(pdf);
}
]]>
</mx:Script>


<mx:HBox width="100%">
<mx:TextInput id="pdfName"/>
<mx:Button label="Load" click="loadPDF(pdfName.text)" />
</mx:HBox>
<mx:Spacer id="container" />
</mx:WindowedApplication>

ahjavier
07-16-2009, 08:24 AM
function fileSelected(evt:Event)
{

loadPDF(evt.target.name); // You're just getting the name of the file, thats why you only can open files within your app folder...


}


try something like this.. should work..

function fileSelected(evt:Event)
{
var dir:String = File(evt.currentTarget).nativePath; //get the entire file path
loadPDF(dir);

}