Flash
  Home arrow Flash arrow Page 4 - 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  
Dedicated Servers  
Actuate Whitepapers 
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 / 1
    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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Using the File System API - Asynchronous and Synchronous Versions of Methods


    (Page 4 of 4 )

    Some of the methods of the File class (such as
    File.copyFile()andFile.copyFileAsync()) and of theFileStream class have both synchronous and asynchronous versions.

    The synchronous methods don’t relinquish control until the file operation is complete. The asynchronous methods run in the background, allowing other ActionScript processes to take place at the same time. When the asynchronous file operation finishes, an event is dispatched to notify listeners that it is done.

    Here’s an example of copying a file using the synchronouscopyTo()method:

      var file1:File = File.documentsDirectory.
      resolve("ApolloTest/test.txt");
      var file2:File = File.documentsDirectory.
      resolve("ApolloTest/copy of test.txt");
      file1.copyTo(file2);
      trace("Not output until the file is copied.");

    Here’s an example of copying a file using the asynchronouscopyToAsync()method:

      var file1:File = File.documentsDirectory.
      resolve("ApolloTest/test.txt");
      var file2:File = File.documentsDirectory.
      resolve("ApolloTest/copy of test.txt");
      file1.copyToAsync(file2);

      file1.addEventListener(Event.COMPLETE, completeHandler);
      trace("This line executes before the complete event.");
      trace("So does this line.");

      private function completeHandler(event:Event):void {
        trace("Done.");
      }

    The following table lists the asynchronous methods of theFile class (all of which have synchronous counterparts) and the events that can fire after the method is called:

    Asynchronous File method Events
    copyToAsync() complete,ioError
    deleteDirectoryAsync( ) complete,ioError
    deleteFileAsync() complete,ioError
    listDirectoryAsync()

    directoryListing,ioError

    moveToAsync() complete,ioError
    moveToTrashAsync( ) complete,ioError

    When you open a file, use either theopen()oropenAsync()method of theFileStreamobject. The first opens the file for synchronous operations, and the second opens the file for asynchronous operations. For more information, see “The open( ) and openAsync( ) Methods” later in this chapter.

    Use asynchronous methods whenever you want to make sure that other essential ActionScript-driven processes—such as progress bar animation—continue while the file operations take place. For example, you could use theopen()(synchronous) method of aFileStreamobject if you are going to write a small file (1 MB or less) and use theopenAsync()method when writing larger files, or when the file size is unknown.

    For more information on asynchronous methods in general, see the “Handling Events” chapter in Programming ActionScript 3.0, which is available at:

    http://livedocs.macromedia.com/flex/2/docs/Part5_ProgAS.html

    Please check back next week for the conclusion to this article.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · 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

    - 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
    - Fun Things to Do with Movie Clips in Flash MX
    - Referencing Movie Clips in Flash MX







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway