8.3. Browse for Files
The last section of this Chapter demonstrates how to allow users to select a file or a directory by browsing their file systems with their native operating system's browse dialog. The sample code in Listing 8-9 shows two methods for opening the native browse dialog. The first uses the browseForOpen function of the File class, which is supplied a single argument for the label of the dialog box. A second argument to limit the browse dialog to specific file types is also available as an optional argument. An eventListener has been added to show the user's selection. The results can be seen in Figures 8-10 and 8-11. The second example uses the browseForDirectory function of the File class, which accepts a single argument for the browse dialog label. The results of this can be seen in Figures 8-12 and 8-13.
Example 8-9. Code for using the operating system's native browse dialog within AIR
<?xml version="1.0" encoding="utf-8"?> <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> <mx:Script> <![CDATA[ import flash.filesystem.File; import mx.controls.Alert; // Allows user to select a file private function browseForOpen():void { var file:File = new File(); file.addEventListener(Event.SELECT,openHandler); file.browseForOpen("Select a File" ); } private function openHandler(event:Event):void { Alert.show(event.target.nativePath,"Selected File" ); } // Allows user to select a directory private function browseForDirectory(): |
Get Beginning Adobe® AIR™: Building Applications for the Adobe Integrated Runtime now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.