ActionScript 3.0 Language and Components Reference | All Packages | All Classes | Language Elements | Index | Appendixes | Conventions | Frames No Frames |
IDataOutput

Package | flash.utils
Interface | public interface IDataOutput
Implementors | ByteArray, Socket

Language Version : | ActionScript 3.0

Player Version : | Flash Player 9

The IDataOutput interface provides a set of methods for writing binary data. This interface is the I/O counterpart to the IDataInput interface, which reads binary data. The IDataOutput interface is implemented by the Socket and ByteArray classes.

All IDataInput and IDataOutput operations are "bigEndian" by default (the most significant byte in the sequence is stored at the lowest or first storage address), and are nonblocking.

Sign extension matters only when you read data, not when you write it. Therefore, you do not need separate write methods to work with `IDataInput.readUnsignedByte()` and `IDataInput.readUnsignedShort()`. In other words:

- Use `IDataOutput.writeByte()` with `IDataInput.readUnsignedByte()` and `IDataInput.readByte()`.
- Use `IDataOutput.writeShort()` with `IDataInput.readUnsignedShort()` and `IDataInput.readShort()`.

View the examples

See also

IDataInput interface
endian
Socket class
URLStream class
ByteArray class

Public Properties

| Property | Defined By
--- | --- | ---
|  | endian : String The byte order for the data, either the "bigEndian" or "littleEndian" constant from the Endian class. | IDataOutput
|  | objectEncoding : uint Used to determine whether the ActionScript 3.0, ActionScript 2.0, or ActionScript 1.0 format should be used when writing to, or reading binary data. | IDataOutput

Public Methods

| Method | Defined By
--- | --- | ---
|  | writeBoolean(value:Boolean):void Writes a Boolean value. | IDataOutput
|  | writeByte(value:int):void Writes a byte. | IDataOutput
|  | writeBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0):void Writes a sequence of length bytes from the specified byte array, bytes, starting offset(zero-based index) bytes into the byte stream. | IDataOutput
|  | writeDouble(value:Number):void Writes an IEEE 754 double-precision (64-bit) floating point number. | IDataOutput
|  | writeFloat(value:Number):void Writes an IEEE 754 single-precision (32-bit) floating point number. | IDataOutput
|  | writeInt(value:int):void Writes a 32-bit signed integer. | IDataOutput
|  | writeMultiByte(value:String, charSet:String):void Writes a multibyte string to the byte stream using the specified character set. | IDataOutput
|  | writeObject(object:*):void Writes an object to the byte stream or byte array in AMF serialized format. | IDataOutput
|  | writeShort(value:int):void Writes a 16-bit integer. | IDataOutput
|  | writeUnsignedInt(value:uint):void Writes a 32-bit unsigned integer. | IDataOutput
|  | writeUTF(value:String):void Writes a UTF-8 string to the byte stream. | IDataOutput
|  | writeUTFBytes(value:String):void Writes a UTF-8 string. | IDataOutput

Property Detail

endian | property

`endian:String` [read-write]

Language Version : | ActionScript 3.0

Player Version : | Flash Player 9

The byte order for the data, either the "bigEndian" or "littleEndian" constant from the Endian class.

Implementation
`public function get endian():String`
`public function set endian(value:String):void`

See also

Endian class

objectEncoding | property |

`objectEncoding:uint` [read-write]

Language Version : | ActionScript 3.0

Player Version : | Flash Player 9

Used to determine whether the ActionScript 3.0, ActionScript 2.0, or ActionScript 1.0 format should be used when writing to, or reading binary data. The value is a constant from the ObjectEncoding class.

Implementation
`public function get objectEncoding():uint`
`public function set objectEncoding(value:uint):void`

See also

IDataInput.readObject()
writeObject()
ObjectEncoding class
Method Detail

writeBoolean | () | method

`public function writeBoolean(value:Boolean):void`

Language Version : | ActionScript 3.0

Player Version : | Flash Player 9

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` Flash Player writes a 1; if `false`, Flash Player writes a 0.

writeByte | () | method |

`public function writeByte(value:int):void`

Language Version : | ActionScript 3.0

Player Version : | Flash Player 9

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.

writeBytes | () | method |

`public function writeBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0):void`

Language Version : | ActionScript 3.0

Player Version : | Flash Player 9

Writes a sequence of `length` bytes from the specified byte array, `bytes`, starting `offset`(zero-based index) bytes into the byte stream.

If the `length` parameter is omitted, the default length of 0 is used; Flash Player writes the entire buffer starting at `offset`. 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.
| `offset:uint` (default = `0`)`` — A zero-based index indicating the position into the array to begin writing.
| `length:uint` (default = `0`)`` — An unsigned integer indicating how far into the buffer to write.

writeDouble | () | method |

`public function writeDouble(value:Number):void`

Language Version : | ActionScript 3.0

Player Version : | Flash Player 9

Writes an IEEE 754 double-precision (64-bit) floating point number.

Parameters

| `value:Number` — A double-precision (64-bit) floating point number.

writeFloat | () | method |

`public function writeFloat(value:Number):void`

Language Version : | ActionScript 3.0

Player Version : | Flash Player 9

Writes an IEEE 754 single-precision (32-bit) floating point number.

Parameters

| `value:Number` — A single-precision (32-bit) floating point number.

writeInt | () | method |

`public function writeInt(value:int):void`

Language Version : | ActionScript 3.0

Player Version : | Flash Player 9

Writes a 32-bit signed integer.

Parameters

| `value:int` — A byte value as a signed integer.

writeMultiByte | () | method |

`public function writeMultiByte(value:String, charSet:String):void`

Language Version : | ActionScript 3.0

Player Version : | Flash Player 9

Writes a multibyte string to the byte stream using the specified character set.

Parameters

| `value:String` — The string value to be written.
| `charSet:String` — The string denoting the character set to use. Possible character set strings include `"shift-jis"`, `"cn-gb"`, `"iso-8859-1"` and others. For a complete list, see Supported Character Sets.

writeObject | () | method |

`public function writeObject(object:*):void`

Language Version : | ActionScript 3.0

Player Version : | Flash Player 9

Writes an object to the byte stream or byte array in AMF serialized format.

Parameters

| `object:*` — the object to be serialized

See also

objectEncoding

writeShort | () | method |

`public function writeShort(value:int):void`

Language Version : | ActionScript 3.0

Player Version : | Flash Player 9

Writes a 16-bit integer. The low 16 bits of the parameter are used. The high 16 bits are ignored.

Parameters

| `value:int` — A byte value as an integer.

writeUnsignedInt | () | method |

`public function writeUnsignedInt(value:uint):void`

Language Version : | ActionScript 3.0

Player Version : | Flash Player 9

Writes a 32-bit unsigned integer.

Parameters

| `value:uint` — A byte value as an unsigned integer.

writeUTF | () | method |

`public function writeUTF(value:String):void`

Language Version : | ActionScript 3.0

Player Version : | Flash Player 9

Writes a UTF-8 string to the byte stream. The length of the UTF-8 string in bytes is written first, as a 16-bit integer, followed by the bytes representing the characters of the string.

Parameters

| `value:String` — The string value to be written.

Throws

| `RangeError` — If the length is larger than 65535.

writeUTFBytes | () | method |

`public function writeUTFBytes(value:String):void`

Language Version : | ActionScript 3.0

Player Version : | Flash Player 9

Writes a UTF-8 string. Similar to `writeUTF()`, but does not prefix the string with a 16-bit length word.

Parameters

| `value:String` — The string value to be written.

Examples How to use examples
DataOutputExample.as
The following example uses the class `DataOutputExample` to write a boolean and the double-precision floating-point representation of pi to a byte array. This is accomplished using the following steps:

1. Declare a new ByteArray object instance `byteArr`.
2. Write the byte-equivalent value of the Boolean `false` and the double-precision floating-point equivalent of the mathematical value of pi.
3. Read back the boolean and double-precision floating-point number.

Notice how a code segment is added at the end to check for end of file errors to ensure that the byte stream is not read past its end.

    package {
        import flash.display.Sprite;
        import flash.utils.ByteArray;
        import flash.errors.EOFError;

        public class DataOutputExample extends Sprite {
            public function DataOutputExample() {
                var byteArr:ByteArray = new ByteArray();

                byteArr.writeBoolean(false);
                byteArr.writeDouble(Math.PI);

                byteArr.position = 0;

                try {
                    trace(byteArr.readBoolean()); // false
                }
                catch(e:EOFError) {
                    trace(e);           // EOFError: Error #2030: End of file was encountered.
                }

                try {
                    trace(byteArr.readDouble());    // 3.141592653589793
                }
                catch(e:EOFError) {
                    trace(e);           // EOFError: Error #2030: End of file was encountered.
                }

                try {
                    trace(byteArr.readDouble());
                }
                catch(e:EOFError) {
                    trace(e);        // EOFError: Error #2030: End of file was encountered.
                }
            }
        }
    }

Submit Feedback on LiveDocs
© 2004-2008 Adobe Systems Incorporated. All rights reserved.
Tue May 20 2008, 04:02 AM -07:00