Hi. I'm trying to get my AIR application to load a PDF document from the dialog box using File Reference Class.
With the code that I have if I use a regular Loader then I can get a PNG image to load into a container and display on the screen. But PDF's require HTML Loader which seems not to accept event.target.data because it is expecting a String.
This is the error I got
TypeError: Error #1034: Type Coercion failed: cannot convert "[object FileReference]" to flash.net.URLRequest.
at test_pdf_load_from_dialogfla_fla::MainTimeline/loadFile()[test_pdf_load_from_dialogfla_fl a.MainTimeline::frame1:61]
[UnloadSWF] test_pdf_load_from_dialogfla.swf
Here is my code:
import flash.net.URLRequest;
import flash.display.MovieClip;
import flash.html.HTMLLoader;
import flash.net.FileReference;
import flash.net.FileFilter;
var file:FileReference=new FileReference();
var container:MovieClip=new MovieClip();
addChild(container);
var i:Number=1;
// button is an object on the stage, not being called via actionscript
button.addEventListener(MouseEvent.CLICK, showDialog);
var myFile:FileReference;
var myFileLoader:HTMLLoader;
function showDialog(e:MouseEvent):void{
myFile=new FileReference();
var PDFFileType:FileFilter=new FileFilter("PDFs (*.pdf)","*.pdf");
myFile.browse([PDFFileType]);
myFile.addEventListener(Event.SELECT, selectFile);
}
function selectFile(e:Event):void{
myFile.addEventListener(Event.COMPLETE, loadFile);
myFile.load();
}
myFileLoader=new HTMLLoader();
function loadFile(e:Event):void{
myFileLoader.load((e.target).toString());
}
(with the new forum selection I also can't seem to put this topic into the ActionScript location of the forum for Flash Pro.)