Write to file flash as3




















For details, see Initializing a FileStream object, and opening and closing files. Building a text-file editor. Reading and writing from an XML preferences file. Adobe Flash Platform. Workflow for reading and writing files Adobe AIR 1.

The workflow for reading and writing files is as follows. Initialize a File object that points to the path. Initialize a FileStream object.

Call the open method or the openAsync method of the FileStream object. If you opened the file asynchronously using the openAsync method , add and set up event listeners for the FileStream object.

Include code for reading and writing data, as needed. For example, the following code reads the data from a file into a ByteArray object named bytes :. Similarly, the following code writes data from a ByteArray named bytes to a file:. However, often you do not want to store the data in an ActionScript ByteArray object.

And often the data file is in a specified file format. For example, the data in the file may be in a text file format, and you may want to represent such data in a String object. For this reason, the FileStream class includes read and write methods for reading and writing data to and from types other than ByteArray objects. For example, the readMultiByte method lets you read data from a file and store it to a string, as in the following code:. The second parameter of the readMultiByte method specifies the text format that ActionScript uses to interpret the data "iso" in the example.

If the FileStream object is already open, calling the method closes the file before opening and no further events including close are delivered for the previously opened file. On systems that support file locking, a file opened in "write" or "update" mode FileMode. Once you are done performing operations on the file, call the close method of the FileStream object.

Some operating systems limit the number of concurrently open files. Parameters file : File — The File object specifying the file to open. Opens the FileStream object asynchronously, pointing to the file specified by the file parameter. If the fileMode parameter is set to FileMode. UPDATE , AIR reads data into the input buffer as soon as the file is opened, and progress and open events are dispatched as the data is read to the input buffer. Reads a Boolean value from the file stream, byte stream, or byte array.

A single byte is read and true is returned if the byte is nonzero, false otherwise. Reads the number of data bytes, specified by the length parameter, from the file stream, byte stream, or byte array. The bytes are read into the ByteArray objected specified by the bytes parameter, starting at the position specified by offset.

The default value of 0 causes all available data to be read. Reads an IEEE double-precision floating point number from the file stream, byte stream, or byte array.

Reads an IEEE single-precision floating point number from the file stream, byte stream, or byte array. Reads a multibyte string of specified length from the file stream, byte stream, or byte array using the specified character set.

Parameters length : uint — The number of bytes from the byte stream to read. Possible character set strings include "shift-jis" , "cn-gb" , "iso" , and others. For a complete list, see Supported Character Sets. For example, a value for the charSet parameter, as in myTest. Reads an object from the file stream, byte stream, or byte array, encoded in AMF serialized format.

Reads a UTF-8 string from the file stream, byte stream, or byte array. The string is assumed to be prefixed with an unsigned short indicating the length in bytes. Reads a sequence of UTF-8 bytes from the byte stream or byte array and returns a string. Parameters length : uint — The number of bytes to read.

Truncates the file at the position specified by the position property of the FileStream object. Bytes from the position specified by the position property to the end of the file are deleted. The file must be open for writing. Writes a Boolean value. A single byte is written according to the value parameter, either 1 if true or 0 if false.

Parameters value : Boolean — A Boolean value determining which byte is written. If the parameter is true , 1 is written; if false , 0 is written. Writes a byte. The low 8 bits of the parameter are used; the high 24 bits are ignored.

Parameters value : int — A byte value as an integer. Writes a sequence of bytes from the specified byte array, bytes , starting at the byte specified by offset using a zero-based index with a length specified by length , into the file stream, byte stream, or byte array.

If the length parameter is omitted, the default length of 0 is used and the entire buffer starting at offset is written. If the offset parameter is also omitted, the entire buffer is written. If the offset or length parameter is out of range, they are clamped to the beginning and end of the bytes array.

Parameters bytes : ByteArray — The byte array to write. Parameters value : Number — A double-precision bit floating point number. Parameters value : Number — A single-precision bit floating point number. Parameters value : int — A byte value as a signed integer. Writes a multibyte string to the file stream, byte stream, or byte array, using the specified character set. Parameters value : String — The string value to be written.

Writes an object to the file stream, byte stream, or byte array, in AMF serialized format. Writes a bit integer. The low 16 bits of the parameter are used; the high 16 bits are ignored. Parameters value : uint — A byte value as an unsigned integer. Writes a UTF-8 string to the file stream, byte stream, or byte array. The length of the UTF-8 string in bytes is written first, as a bit integer, followed by the bytes representing the characters of the string. Writes a UTF-8 string.

Similar to writeUTF , but does not prefix the string with a bit length word. Indicates that the stream has been closed by an explicit call to the close method. Filters: Retrieving Data from Server Retrieving Data from Server Classes x. Package flash. Files can be opened synchronously by calling the open method or asynchronously by calling the openAsync method.

More examples Reading and writing files. Public Properties. Hide Inherited Public Properties. Show Inherited Public Properties.

A reference to the class object or constructor function for a given object instance.



0コメント