Working With the File System API in AIRAdobe's new Integrated Runtime (AIR) will be released at some point this year (a beta is currently available here). The release of AIR will bring new possibilities in how applications communicate with client machines. Previous to the Adobe Integrated Runtime, Flash applications adhered to a security model that drastically handicapped what your applications could and couldn't do. For more information on the general Flash player security model see this page; for more info on Flash player security and Flex 2. With AIR, all of the following are now possible: The ability to. Flash Platform Doc Team Developer doc updates. If you are writing or planning to write apps for AIR 2.5 for TV. AIR for TV apps can access the device’s filesystem. How to Install Adobe AIR on Ubuntu. Navigate the filesystem > /usr/bin/Adobe AIR installer Click > Open. The icon should change and you can now install AIR apps. Adobe AIR - Save image on hard drive. Adobe AIR doesn't save file with file's extension. Action. Script objects and classes to the file systemget system information on files and directories. In this blog post I'll talk about what new classes are available in Flex 3 (Flex . In my next post I'll show an example of how to use the file system API in a real- world application. A new package is included in Flex 3 called flash. File, File. Mode, and File. Stream. Let's take a closer look at each of these new classes. File. The file class is a representation of a file or directory on the file system. It's also used to represent a file or directory that you wish to create. Included in the File class are properties and methods for getting information about the file system and for performing operations on the file system like creating or deleting files and directories. Coupling the File class with the File. Stream class (which we'll examine in a minute) you can read and write binary and text files on the client machine. The first important aspect of the File class is how it abstracts file system paths for you making it easier to write applications. If you remember, AIR is a cross- platform runtime available on Windows, Macintosh and - in the future - Linux. These operating systems represent file and directory paths in totally different ways. For example, my home directory on Windows might be C: \Documents and Settings\aaron\ while on a Mac it would be /Users/aaron/. The File class has several static properties that represent operation system agnostic paths. File. app. Storage. Directory. Every AIR application is given a storage directory. This is a great place to store preference files, cache files, log files, or any other file specific to the application running on the client. Example application storage directories are /Users/aaron/Library/Preferences/. As an example, the application ID for my twitter. AIR app is com. trajiklyhip. AIR. This ID is set by the developer in the AIR application descriptor file. File. app. Resource. Directory. This is the directory where an AIR application is installed. For instance /Users/aaron/Applications/ on Mac and C: \Documents and Settings\aaron\Local Settings\Application Data\. Example: /Users/aaron/ on Mac and C: \Documents and Settings\aaron\ on Windows. This directory serves as the base directory for all subsequent directories described below. File. desktop. Directory. The users desktop directory. Example: /Users/aaron/Desktop/ on Mac and C: \Documents and Settings\aaron\Desktop\ on Windows. File. documents. Directory. The users documents directory Example: /Users/aaron/Documents on Mac and C: \Documents and Settings\aaron\My Documents\ on Windows. File. current. Directory. This is the directory where the AIR application was launched. Note, users can move applications from their initial location to other locations on the file system. Thus, the value of this static property may differ from the value stored in File. Resource. Directory. In order to make use of these static properties you must first create an instance of the File class. For example, to create an instance of the File class that points to the users documents directory you would write the following code: import flash. File; var docs. Directory: File = File. Directory; Once you have an instance of the File class created there are several properties of the instance that describe the file or directory the instance references. These include: File. Directory. Whether the instance refers to a directory (true) or a file (false). Checking the value of this property is useful before calling any directory specific functions like File. Directory(), which returns the list of files and directories stored in the File instance. File. is. Hidden. Whether the instance refers to a hidden directory or file on the file system. File. exists. A boolean value indicating whether the resource exists. You should check this value before attempting to write or read a specified file or directory. File. native. Path. This property reveals the operating system specific path to a file or directory. From the example code above (File. Directory) this value might be /Users/aaron/Documents on Mac and C: \Documents and Settings\aaron\My Documents\ on Windows. File. url. This property is the reverse of File. Path and reveals the operating system independent path to a file or directory preceded by a URL scheme. From the example code above this value might be file: ///Users/aaron/Documents on Mac and file: //C: /Documents%2. Settings/aaron/My Documents/ on Windows. File. parent. The parent directory (as an instance of File) of the File instance. Other useful properties of a File instance include: File. Date, File. modification. Date, File. name, File. File. type, File. File. extension. Note, some of these are only valid for instances of the File class that point to files. Returning to the previous example, what if you wanted to trace the value of the user's documents directory? You can't just write trace(docs. Directory) as docs. Directory is a File instance, and not a string. Using the properties described above, you could write the following: import flash. File; var docs. Directory: File = File. Directory; trace(docs. Directory. url); // file: ///Users/aaron/Documents. If you wanted to create a reference to an actual file in the user's documents directory and determine whether it exists or not you would write: import flash. File; var my. File: File = File. Directory. resolve(. This class relates to various modes with which a file can be opened. In Cold. Fusion, this type of low- level access is mostly hidden. In fact, you don't even have to explicitly open and close files in order to work with them. In AIR, you must perform these steps. When it comes time to open a file you'll need to decide how you wish to open the file based on what you are going to be doing with it. Here are your options - which are constant values (hence the upper case) of the File. Mode class. You use these constants in conjunction with the File. Stream class (covered below) when opening files. File. Mode. READThe file is opened in read- only mode and must already exist in the given location. An File I/O exception will be thrown if you attempt to open a non- existing file in File. Mode. READ mode. File. Mode. WRITEThe file is opened in write- only mode. If the file does not exist in the given location it will be created. If the file does exist, it will be completely overwritten. File. Mode. UPDATEThe file is opened in read/write mode. Data can be written to any position in the file or appended to the end. If the file does not exist it will be created automatically. File. Mode. APPENDThe file is opened in write- only mode and data is automatically written to the end of the file. If the file does not exist it will be created automatically. File. Stream. The File. Stream class is used to read and write files. It's where all the real heavy- lifting is done in terms of opening connections to files, writing to those files, and closing the files. Included in the class are some 2. Action. Script objects to files. The type of read/write method you choose will determine how data is encoded in files as well as whether the reading/writing actions are performed synchronously or asychronously. If you want to specify a different character encoded, the Filestream. Multi. Byte() and File. Stream. write. Multi. Byte() methods are available. These last two methods take two arguments, the second of which is the character encoding you want to use. Here are two examples of writing UTF- 8 encoded data into a file. The first does so synchronously and the second asynchronously. Which method you choose should be based on your application strategy but a good rule is write large files - that may take a long time to write - asynchronously. This will allow your application to continue functioning without waiting on the file to write to the file system. Write UTF- 8 encoded string data to a file on the user's desktop synchronously. The overall File API included in Flex 3 is relatively easy to work with and extremely powerful. Using it properly opens your desktop applications to a whole new realm of possibilities. Stay tuned in the near future to read more about real- world ways to utilize these new classes in your applications. This package is only available to content running in Adobe AIR. Classes Class. Description File. A File object represents a path to a file or directory. File. Mode. The File. Mode class defines string constants used in the file. Mode parameter of. Async() methods of the File. Stream class. File. Stream. A File. Stream object is used to read and write files. Storage. Volume. A Storage. Volume object includes properties defining a mass storage volume. Storage. Volume. Info. The Storage. Volume. Info object dispatches a Storage. Volume. Change. Event object when a. Mon Sep 1. 2 2. 01.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2016
Categories |