Flash
  Home arrow Flash arrow Page 2 - Using the File System API
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Moblin 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
FLASH

Using the File System API
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-03-13

    Table of Contents:
  • Using the File System API
  • Accessing Files and Directories
  • URI Schemes
  • Asynchronous and Synchronous Versions of Methods

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Using the File System API - Accessing Files and Directories


    (Page 2 of 4 )

    Apollo applications can run on multiple platforms, including Windows and Mac OS. The Apollo file API uses platform-neutral code syntax so you don’t have to write any OS-specific code.

    For example, the way you represent a path to a file differs between Mac OS and Windows:

    1. A typical file path on Mac OS is /Users/joe/Documents/test.txt
    2. A typical file path on Windows is C:\Documents and Settings\joe\My Documents\test.txt

    However, you can use exactly the same Apollo components, classes, methods, and properties to access files in either operating system.

    An ActionScriptFile object is a pointer to a file or directory. TheFileclass includes the static propertydocumentsDirectory, which contains aFileobject that points to the user’s documents directory. This is the My Documents directory on Windows, and it is the Documents subdirectory of the user directory on Mac OS, as illustrated in the following code:

      trace(File.documentsDirectory.nativePath)
           // On Windows:
           //       C:\Documents and Settings\joe\MyDocuments
           // On Mac OS:  /Users/joe/Documents

    Once you point aFileobject to a directory, you can use theresolve()method to modify it to point to a file or subdirectory within that directory (or within a subdirectory). For example, the following code creates an Apollo Test subdirectory of the user’s documents directory:

      var newDir:File = File.documentsDirectory;
      newDir = newDir.resolve("ApolloTest");
      newDir.createDirectory();

    AFileobject can point to either a file or a directory. Also, aFileobject may point to a file or directory that does not exist, as in the previous example. This lets you point aFileobject to a directory location that you wish to create.

    File Class Properties for Accessing Common Directory Locations

    The Fileclass includes the following static properties, which point to commonly used directory locations:

    Property

    Description

    File.appStorageDirectory

    Each installed Apollo application is given a unique application storage directory. This is a good place to store files that the application may want to maintain but that the user will probably need not see. This may include log files, cache files, and preferences files.

    File.appResourceDirectory

    The application’s install directory.

    File.currentDirectory

    This is the directory from which the file was launched. You may use this property to resolve the file path of any command-line parameters that were passed to the application.

    File.desktopDirectory

    This is the user’s desktop directory.

    Continued

    Property

    Description

    File.documentsDirectory

    This is the My Documentsdirectory on Windows, and the Documentssubdirectory of the user directory on Mac OS.

    File.userDirectory

    This is the user’s home directory. For example, on Mac OS, it is the Users/ usernamedirectory, and on Windows it is typically c:\\Document and Settings\username.

    The url and nativePath Properties of a File Object

    The urlproperty of aFile object returns the location of a file or folder as a platform-independent string that begins with a URL scheme, such asfile, as in the following:

      var directory:File = File.userDirectory;
      trace(directory.url)
       
    // on Windows: file:///C:/Documents%20and%20Settings
       
    // on Mac OS: file:///Users

    whereas thenativePath property of aFileobject returns a string that is unique to Windows or Mac OS. For example, you can use this code to point to a specific file on a Windows computer:

      var file:File = new File();
      file.nativePath = "c:/ApolloTest/surprise.txt";

    However, it is generally better to start with one of the static properties listed in the table in the previous section (such as theFile.appStorageDirectory)—that point to known directories on the operating system—and then use theresolve()method to create to a relative path based on that directory, as in this code:

      var logFile:File = File.appStorageDirectory;
      logFile = logFile.resolve("log.txt");

    Use the application store directory to store files that you want your application to be able to access in the future but that the end user may not need to know about. For instance, this is a good place to store preferences files.

    More Flash Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "Apollo for Adobe Flex Developer's Pocket...
     

    Buy this book now. This article is excerpted from chapter four of the book Apollo for Adobe Flex Developer's Pocket Guide, written by Mike Chambers, Rob Dixon and Jeff Swartz (O'Reilly, 2007; ISBN: 0596513917). Check it out today at your favorite bookstore. Buy this book now.

    FLASH ARTICLES

    - Organizing Frames and Layers for Flash Anima...
    - Organizing Frames and Layers
    - Using XML and ActionScript with Flex Applica...
    - Interfaces and Events with ActionScript and ...
    - Manipulating Data with ActionScript in Flex ...
    - ActionScript Syntax for Flex Applications
    - ActionScript in Flex Applications
    - A Closer Look at Apollo`s File System API
    - Using the File System API
    - ActionScript 101
    - Flash Buttons
    - Advanced Flash Animation
    - Creating Your First Animated Movie with Flas...
    - Flash: Building Blocks
    - Building Preloaders






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT