next up previous contents
Next: Launching external applications Up: Tutorials Previous: Building windowless projectors   Contents

Accessing disk files

SWFKit provides three objects for operating disk files or folders, which are the File object, the Folder object, and the FileStream object. The File and Folder objects can be used to get the properties of a file or a folder. For example, you can use the File object to get the modified time of a file, or get its size, file type, short name, parent path, etc. Moreover, you can use them to determine whether a file or folder exists. The following code is used to get properties of a file in FFish script:
var fileName = "c:\\sounds\\demo.mp3";
if (File.exists(fileName))
{
    var f = new File(fileName);
    trace(f.size);
    trace(f.shortName);
}

Furthermore, the File object and the Folder object can also be used to copy, move or delete files or folders. For example, copy a file

var file = new File("c:\\sounds\\demo.mp3");
file.copy("d:\\demo.mp3");

The FileStream object is used to read data from a file or write data to a file. It can not only read or write strings, but read or write binary data. For example, the get method is used to read a byte from a file, while the readLine method can read a line of string from a file. The following Action script code for Flash 8 shows how to write a XML object to a file

import SWFKit.*;

var xml = new XML;
// XML operations
...
...

// Save a XML file
var fs = new FileStream("c:\\my.xml", "w");
fs.writeLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
fs.write(xml.toString());
fs.close();
fs.Release();


next up previous contents
Next: Launching external applications Up: Tutorials Previous: Building windowless projectors   Contents
Copyright ©2000-2010 Shanghai TopCMM Software Technologies. All Rights Reserved.