Tuesday, March 8, 2011

Introduction to Adobe AIR: Part 7

In this tutorial we will create a simple AIR application in Flash CS5 that displays the user's files and directories on their desktop.

To do that, we'll be using the File class.

The File class is only available to AS3 when creating AIR applications. This class allows us to do things that we couldn't do before, such as create, delete and display files and directories (with or without the browser window to select directory/files).

Let's get started. Open up Flash, start a new AIR project. Create a new List component, then put it on stage and call it myList. This is the container that we will put the files and directories to.

Enter this code:

import flash.filesystem.File;
import fl.data.DataProvider;

myList.labelField = "name";  
myList.dataProvider = new DataProvider(File.desktopDirectory.getDirectoryListing());

If you test your Flash movie now, you will see that the list now contains all the files and directories you have on your desktop. Actually, it contains the names of all the files and directories. You can change the labelField property of the list to another property of the file, such as creationDate, extension, modificationDate, nativePath, size and many more.

Instead of desktopDirectory, we can use documentDirectory, applicationDirectory, applicationStorageDirectory or userDirectory.

That's all for now.

Thanks for reading!


Related:

Introduction to Adobe AIR: Part 1
Introduction to Adobe AIR: Part 2
Introduction to Adobe AIR: Part 3
Introduction to Adobe AIR: Part 4
Introduction to Adobe AIR: Part 5
Introduction to Adobe AIR: Part 6
Introduction to Adobe AIR: Part 8
Introduction to Adobe AIR: Part 9

1 comment:

digital signature Adobe Reader said...

Very informative blog indeed.The example code you gave is really nice.I have tried this and after some minor modifications it worked very fine for me.Thanks man.

Post a Comment