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

by Peter deHaan on December 23, 2008 · 3 comments

in File

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… read them below or add one }

1 Mitesh 07.06.09 at 10:35 pm

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 07.15.09 at 3:01 am

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

3 Swapnil Shirke 11.30.09 at 9:46 pm

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

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: