Skip to content
Dec 23 /

Browsing for directories on a user’s computer using Adobe AIR

The following example shows how you can browse for a directory on the user’s computer in Adobe AIR by calling the browseForDirectory() 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-directories-on-a-users-computer-using-adobe-air/ -->
<mx:WindowedApplication name="File_browseForDirectory_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.browseForDirectory("Please select a directory...");
            }
 
            private function file_select(evt:Event):void {
                lbl.text = file.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>

3 Comments

leave a comment
  1. Mitesh / Jul 6 2009

    Hii,i want that whenever i do browseforOpen……whenever i get the dialog box for selecting files
    ,The label text field in name should get empty…..ne help

  2. Mitesh / Jul 15 2009

    hii i want that the browse for directory box……should not give the browse for folder as title …ne idea

  3. Swapnil Shirke / Nov 30 2009

    Nice work Peter,
    This was of very help to me…

Leave a Comment

Spam Protection by WP-SpamFree