View Full Version : File Browse Box
03-06-2008, 07:56 PM
Does anybody have an example of how to create a file browse dialog box that will open (xml file) the selected file in the AIR app. I've been looking, but everything I see has to do with selecting a file and uploading it. I want to select a file and open it.
03-11-2008, 12:29 AM
you are looking for "browseForOpen". This will open a native file dialog and, when the user selects a file, returns an event with the native path.
the code below is fragmentary, but should give a sense of how you pull in a string and cast it to an XML object.
private var _data:String;
private var _dataXML:XML;
private var fileToOpen:File;
var txtFilter:FileFilter = new FileFilter("Text", "*.as;*.css;*.html;*.txt;*.xml"); // file filter object tells open dialog what is selectable
root.browseForOpen("Open a Semester to Edit", [txtFilter]); // open the file
root.addEventListener(Event.SELECT, fileSelected); // event for when user selects a file
var stream:FileStream = new FileStream(); // open filestream
stream.open(fileToOpen, FileMode.READ); // open the file
_data = stream.readUTFBytes(stream.bytesAvailable); // read file
stream.close(); // close file
_dataXML = XML(_data); // cast the string to XML
vBulletin® v3.8.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.