Browsing for individual files on a user’s computer using Adobe AIR

by Peter deHaan on December 23, 2008 · 1 comment

in File

In a previous example, “Browsing for directories on a user’s computer using Adobe AIR”, we saw how you could browse for a directory on the user’s computer in Adobe AIR by calling the browseForDirectory() method on a File object.

The following example shows how you can browse for a single file on the user’s computer in Adobe AIR by calling the browseForOpen() method on a File object.

Full code after the jump.

<?xml version="1.0" encoding="utf-8"?>
<!-- http://airexamples.com/2008/12/23/browsing-for-individual-files-on-a-users-computer-using-adobe-air/ -->
<mx:WindowedApplication name="File_browseForOpen_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">
 
    <mx:Script>
        <![CDATA[
            private var file:File;
 
            private function btn_click(evt:MouseEvent):void {
                file = new File();
                file.addEventListener(Event.SELECT, file_select);
                file.browseForOpen("Please select a file...");
            }
 
            private function file_select(evt:Event):void {
                lbl.text = File(evt.currentTarget).nativePath;
            }
        ]]>
    </mx:Script>
 
    <mx:ApplicationControlBar dock="true">
        <mx:Button id="btn"
                label="Click to browse"
                click="btn_click(event);"
                width="100%" />
    </mx:ApplicationControlBar>
 
    <mx:Label id="lbl" />
 
</mx:WindowedApplication>

{ 1 comment… read it below or add one }

1 dragovian 01.23.10 at 7:18 am

thanks :D

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Previous post:

Next post: