"String" fullName="String" packageName="" relativePath="../../String.html"/> type property of a preDataChange event object. This event object is dispatched before a change is made to component data.

This event has the following properties:

PropertyValue
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
changeTypeIdentifies the type of change to be made.
currentTargetThe object that is actively processing the event object with an event listener.
endIndexIdentifies the index of the last item to be changed.
itemsAn array that lists the items to be changed.
startIndexIdentifies the index of the first item to be changed.
targetThe object that dispatched the event. The target is not always the object listening for the event. Use the currentTarget property to access the object that is listening for the event.
]]>
type property of a preDataChange event object.]]> 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().
]]>
/** * @exampleText The following example uses the class <code>DataOutputExample</code> to write a boolean * and the double-precision floating-point representation of pi to a byte array. This is accomplished * using the following steps: * <ol> * <li>Declare a new ByteArray object instance <code>byteArr</code>.</li> * <li>Write the byte-equivalent value of the Boolean <code>false</code> and the double-precision * floating-point equivalent of the mathematical value of pi.</li> * <li>Read back the boolean and double-precision floating-point number.</li> * </ol> * * <p>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.</p> */ 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. } } } } 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.

]]>
length bytes from the specified byte array, bytes, starting offset(zero-based index) bytes into the byte stream.]]>
value parameter, either 1 if true or 0 if false. ]]> true Flash Player writes a 1; if false, Flash Player writes a 0. ]]> "shift-jis", "cn-gb", "iso-8859-1" and others. For a complete list, see Supported Character Sets. ]]> writeUTF(), but does not prefix the string with a 16-bit length word. ]]>
The Proxy class has no constructor, and you should not attempt to instantiate Proxy. Instead, subclass the Proxy class to override methods such as getProperty and provide custom behavior. If you try to use a method of the Proxy class without overriding the method, an exception is thrown.

And, keep in mind, your own code overriding the methods of the Proxy class can throw exceptions unintentionally. Throwing exceptions when using these methods causes problems because the calling code (using operators like in, is, delete and others) does not expect exceptions. Unless you're already sure your overriding method does not throw exceptions, Adobe recommends using try..catch statements around your implementation of the Proxy class to avoid fatal errors when operators call your methods. For example:

dynamic class MyProxy extends Proxy { flash_proxy override function callProperty(name:~~, ...rest):~~ { try { // custom code here } catch (e:Error) { // respond to error here } }

The Proxy class is a replacement for the Object.__resolve and Object.addProperty features of ActionScript 2.0, which are no longer available in ActionScript 3.0. The Object.addProperty() feature allowed you to dynamically create get and set methods in ActionScript 2.0. Although ActionScript 3.0 provides get and set methods at compile time, you cannot dynamically assign one to an object unless you use the Proxy class.

To avoid collisions with the public namespace, the methods of the Proxy class are in the flash_proxy namespace.

Where methods of the Proxy class take a name argument, name can be either a String or a QName object (if namespaces are being used).

]]>
/** * @internal The following example uses the class <code>ProxyExample</code> in conjunction * with the class <code>CustomArray</code> to show how ???. This is accomplished using the following * steps: * <ol> * <li>.</li> * <li>.</li> * <li>.</li> * <li>:</li> * <ol TYPE = "A"> * <li>.</li> * <li>.</li> * <li>.</li> * </ol> * <li>.</li> * </ol> */ package { import flash.display.Sprite; public class ProxyExample extends Sprite { public function ProxyExample() { var arr:ProxyArray = new ProxyArray(); arr.push(1); arr.push(-2); arr.push(3); arr.push(4); arr.push("five"); trace(arr.length); // 5 trace(arr[0]); // 1 trace(arr[1]); // -2 trace(arr[2]); // 3 trace(arr[3]); // 4 trace(arr.sum()); // 6 arr.clear(); trace(arr); // (empty string) arr[0] = "zero"; trace(arr); // zero } } } import flash.utils.Proxy; import flash.utils.flash_proxy; dynamic class ProxyArray extends Proxy { private var _item:Array; public function ProxyArray() { _item = new Array(); } override flash_proxy function callProperty(methodName:*, ... args):* { var res:*; switch (methodName.toString()) { case 'clear': _item = new Array(); break; case 'sum': var sum:Number = 0; for each (var i:* in _item) { // ignore non-numeric values if (!isNaN(i)) { sum += i; } } res = sum; break; default: res = _item[methodName].apply(_item, args); break; } return res; } override flash_proxy function getProperty(name:*):* { return _item[name]; } override flash_proxy function setProperty(name:*, value:*):void { _item[name] = value; } } undefined. For more information on this behavior, see the ECMA-262 Language Specification, 3rd Edition, section 8.6.2.1. ]]> undefined if the property is not found. ]]> true; otherwise false. ]]> delete operator, this method is called to perform the deletion. ]]> true; otherwise false. ]]> descendant operator. When the descendant operator is used, this method is invoked. ]]> descendant operator.]]> descendant operator. ]]> for...in and for each..in loops on the object to retrieve property index values.

For example:

protected var _item:Array; // array of object's properties override flash_proxy function nextNameIndex (index:int):int { // initial call if (index == 0) { _item = new Array(); for (var x:~~ in _target) { _item.push(x); } } if (index < _item.length) { return index + 1; } else { return 0; } } override flash_proxy function nextName(index:int):String { return _item[index - 1]; } ]]>
for...in and for each..in loops on the object to retrieve the desired names.

For example (with code from Proxy.nextNameIndex()):

protected var _item:Array; // array of object's properties override flash_proxy function nextNameIndex (index:int):int { // initial call if (index == 0) { _item = new Array(); for (var x:~~ in _target) { _item.push(x); } } if (index < _item.length) { return index + 1; } else { return 0; } } override flash_proxy function nextName(index:int):String { return _item[index - 1]; } ]]>
for...in and for each..in loops on the object to retrieve the desired values.

For example (with code from Proxy.nextNameIndex()):

protected var _item:Array; // array of object's properties override flash_proxy function nextNameIndex (index:int):int { // initial call if (index == 0) { _item = new Array(); for (var x:~~ in _target) { _item.push(x); } } if (index < _item.length) { return index + 1; } else { return 0; } } override flash_proxy function nextName(index:int):String { return _item[index - 1]; } ]]>
true if the argument for name is a QName that is also marked as an attribute. ]]>
===) for key comparison on non-primitive object keys. When an object is used as a key, the object's identity is used to look up the object, and not the value returned from calling toString() on it. Primitive (built-in) objects, like Numbers, in a Dictionary collection behave in the same manner as they do when they are the property of a regular object.

The following statements show the relationship between a Dictionary object and a key object:

 var dict = new Dictionary();
 var obj = new Object();
 var key:Object = new Object();
 key.toString = function() { return "key" }
  
 dict[key] = "Letters";
 obj["key"] = "Letters";
  
 dict[key] == "Letters"; // true
 obj["key"] == "Letters"; // true 
 obj[key] == "Letters"; // true because key == "key" is true b/c key.toString == "key"
 dict["key"] == "Letters"; // false because "key" === key is false
 delete dict[key]; //removes the key
 
]]>
===) for key comparison on non-primitive object keys.]]> delete operator. ]]>
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. If insufficient data is available, an EOFError exception is thrown. Use the IDataInput.bytesAvailable property to determine how much data is available to read.

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().
]]>
/** * @exampleText The following example uses the class <code>DataInputExample</code> to write a boolean * and the double-precision floating-point representation of pi to a byte array. This is accomplished * using the following steps: * <ol> * <li>Declare a new ByteArray object instance <code>byteArr</code>.</li> * <li>Write the byte-equivalent value of the Boolean <code>false</code> and the double-precision * floating-point equivalent of the mathematical value of pi.</li> * <li>Read back the boolean and double-precision floating-point number.</li> * </ol> * * <p>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.</p> */ package { import flash.display.Sprite; import flash.utils.ByteArray; import flash.errors.EOFError; public class DataInputExample extends Sprite { public function DataInputExample() { 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. } } } } length parameter, from the 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. ]]> length parameter, from the byte stream or byte array.]]> ByteArray object to read data into. ]]> bytes parameter at which data read should begin. ]]> true is returned if the byte is nonzero, false otherwise. ]]> true if the byte is nonzero, false otherwise. ]]> "shift-jis", "cn-gb", "iso-8859-1", and others. For a complete list, see Supported Character Sets.

Note: If the value for the charSet parameter is not recognized by the current system, then Flash Player uses the system's default code page as the character set. For example, a value for the charSet parameter, as in myTest.readMultiByte(22, "iso-8859-01") that uses 01 instead of 1 might work on your development machine, but not on another machine. On the other machine, Flash Player will use the system's default code page.

]]>
This method is similar to the readUTF() method in the Java IDataInput interface.

]]>
length UTF-8 bytes from the byte stream or byte array and returns a string. ]]> length UTF-8 bytes from the byte stream or byte array and returns a string.]]>
bytesAvailable to ensure that sufficient data is available before trying to read it with one of the read methods. ]]>
Flash Player can interface with a server by using the binary protocol of that server, directly. Some servers use the bigEndian byte order and some servers use the littleEndian byte order. Most servers on the Internet use the bigEndian byte order because "network byte order" is bigEndian. The littleEndian byte order is popular because the Intel x86 architecture uses it. Use the endian byte order that matches the protocol of the server that is sending or receiving data.

]]>
The hexadecimal number 0x12345678 has 4 bytes (2 hexadecimal digits per byte). The most significant byte is 0x12. The least significant byte is 0x78. (For the equivalent decimal number, 305419896, the most significant digit is 3, and the least significant digit is 6).

A stream using the bigEndian byte order (the most significant byte first) writes:

  12 34 56 78
  
]]>
The hexadecimal number 0x12345678 has 4 bytes (2 hexadecimal digits per byte). The most significant byte is 0x12. The least significant byte is 0x78. (For the equivalent decimal number, 305419896, the most significant digit is 3, and the least significant digit is 6).

A stream using the littleEndian byte order (the least significant byte first) writes:

  78 56 34 12
  
]]>
writeExternal() and readExternal() methods of the IExternalizable interface are implemented by a class to allow customization of the contents and format of the data stream (but not the classname or type) for an object and its supertypes. Each individual class must serialize and reconstruct the state of its instances. These methods must be symmetrical with the supertype to save its state. These methods supercede the native Action Message Format (AMF) serialization behavior.

If a class does not implement, nor inherits from a class which implements, the IExternalizable interface, then an instance of the class will be serialized using the default mechanism of public members only. As a result, private, internal, and protected members of a class will not be available.

To serialize private members, a class must use the IExternalizable interface. For example, the following class will not serialize any of its members because they are private:

class Example { private var one:int; private var two:int; }

However, if you implement the IExternalizable interface, you can write to, and read from, the data stream the private members of the class as follows:

class Example implement IExternalizable { private var one:int; private var two:int; public function writeExternal(output:IDataOutput) { output.writeInt(one); output.writeInt(two); } public function readExternal(input:IDataInput) { one = input.readInt(); two = input.readInt(); } }

Note: If a class implements IExternalizable the default serialization no longer applies to instances of that class. If that class inherits public members from a super class, you must carefully manage those members as well.

When a subclass of a class implementing IExternalizable has private members of its own, the subclass must override the methods of IExternalizable, as follows:

public class Base implements IExternalizable { private var one:Boolean; public function writeExternal(output:IDataOutput):void { output.writeBoolean(one); } public function readExternal(input:IDataInput):void { one = input.readBoolean(); } } public class Example extends Base { private var one:String; public override function writeExternal(output:IDataOutput):void { super.writeExternal(output); output.writeUTF(one); } public override function readExternal(input:IDataInput):void { super.readExternal(input); one = input.readUTF(); } }

The IExternalizable interface can also be used to compress data before writing it to a data stream. For example:

class Example implements IExternalizable { public var one:Boolean; public var two:Boolean; public var three:Boolean; public var four:Boolean; public var five:Boolean; public var six:Boolean; public var seven:Boolean; public var eight:Boolean; public function writeExternal(output:IDataOutput) { var flag:int = 0; if (one) flag |= 1; if (two) flag |= 2; if (three) flag |= 4; if (four) flag |= 8; if (five) flag |= 16; if (six) flag |= 32; if (seven) flag |= 64; if (eight) flag |= 128; output.writeByte(flag); } public function readExternal(input:IDataInput) { var flag:int = input.readByte(); one = (flag & 1) != 0; two = (flag & 2) != 0; three = (flag & 4) != 0; four = (flag & 8) != 0; five = (flag & 16) != 0; six = (flag & 32) != 0; seven = (flag & 64) != 0; eight = (flag & 128) != 0; } } ]]>
writeExternal() method. ]]>
Note: The ByteArray class is for advanced ActionScript developers who need to access data on the byte level.

In-memory data is a packed array (the most compact representation for the data type) of bytes, but an instance of the ByteArray class can be manipulated with the standard ActionScript [] (array access) operators. It also can be read and written to as an in-memory file, using methods similar to those in the URLStream and Socket classes.

In addition, zlib compression and decompression are supported, as well as Action Message Format (AMF) object serialization.

Possible uses of the ByteArray class include the following:

  • Creating a custom protocol to connect to a server.
  • Writing your own URLEncoder/URLDecoder.
  • Writing your own AMF/Remoting packet.
  • Optimizing the size of your data by using data types.

]]>
/** * @exampleText The following example uses the class <code>ByteArrayExample</code> to write a Boolean * and the double-precision floating-point representation of pi to a byte array. This is accomplished * using the following steps: * <ol> * <li>Declare a new ByteArray object instance <code>byteArr</code>.</li> * <li>Write the byte-equivalent value of the Boolean <code>false</code> and then check the length and * read it back.</li> * <li>Write the double-precision floating-point equivalent of the mathematical value of pi.</li> * <li>Read back each of the nine bytes written into the byte array.</li> * </ol> * * <p><strong>Note: </strong>when <code>trace()</code> is called on a byte, it prints the decimal equivalent * of the bytes stored in the byte array.</p> * * <p>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.</p> */ package { import flash.display.Sprite; import flash.utils.ByteArray; import flash.errors.EOFError; public class ByteArrayExample extends Sprite { public function ByteArrayExample() { var byteArr:ByteArray = new ByteArray(); byteArr.writeBoolean(false); trace(byteArr.length); // 1 trace(byteArr[0]); // 0 byteArr.writeDouble(Math.PI); trace(byteArr.length); // 9 trace(byteArr[0]); // 0 trace(byteArr[1]); // 64 trace(byteArr[2]); // 9 trace(byteArr[3]); // 33 trace(byteArr[4]); // 251 trace(byteArr[5]); // 84 trace(byteArr[6]); // 68 trace(byteArr[7]); // 45 trace(byteArr[8]); // 24 byteArr.position = 0; try { trace(byteArr.readBoolean() == false); // true } 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. } } } } length parameter, from the byte stream or byte array.]]> length UTF-8 bytes from the byte stream or byte array and returns a string.]]> length bytes from the specified byte array, bytes, starting offset(zero-based index) bytes into the byte stream.]]> length parameter, from the byte stream. The bytes are read into the ByteArray object specified by the bytes parameter, and the bytes are written into the destination ByteArray starting at the position specified by offset. ]]> length parameter, from the byte stream.]]> bytes at which the read data should be written. ]]> 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 offset or length is out of range, they are clamped to the beginning and end of the bytes array.

]]>
length bytes from the specified byte array, bytes, starting offset (zero-based index) bytes into the byte stream.]]>
value parameter, either 1 if true or 0 if false. ]]> true, Flash Player writes a 1; if false, Flash Player writes a 0. ]]> The low 8 bits of the parameter are used. The high 24 bits are ignored.

]]>
"shift-jis", "cn-gb", "iso-8859-1", and others. For a complete list, see Supported Character Sets. ]]> writeUTF() method, but writeUTFBytes() does not prefix the string with a 16-bit length word. ]]> true is returned if the byte is nonzero, false otherwise. ]]> true if the byte is nonzero, false otherwise. ]]> The returned value is in the range -128 to 127.

]]>
The returned value is in the range 0 to 255.

]]>
The returned value is in the range -32768 to 32767.

]]>
The returned value is in the range 0 to 65535.

]]>
The returned value is in the range -2147483648 to 2147483647.

]]>
The returned value is in the range 0 to 4294967295.

]]>
"shift-jis", "cn-gb", "iso-8859-1", and others. For a complete list, see Supported Character Sets.

Note: If the value for the charSet parameter is not recognized by the current system, then Flash Player uses the system's default code page as the character set. For example, a value for the charSet parameter, as in myTest.readMultiByte(22, "iso-8859-01") that uses 01 instead of 1 might work on your development machine, but not on another machine. On the other machine, Flash Player will use the system's default code page.

]]>
length parameter from the byte stream and returns a string. ]]> length parameter from the byte stream and returns a string.]]> After the call, the length property of the ByteArray is set to the new length. The position property is set to the end of the byte array.

The zlib compressed data format is described at http://www.ietf.org/rfc/rfc1950.txt.

]]>
After the call, the length property of the ByteArray is set to the new length. The position property is set to 0.

The zlib compressed data format is described at http://www.ietf.org/rfc/rfc1950.txt.

]]>
System.useCodePage is set to true, the player will treat the data in the array as being in the current system code page when converting. ]]>
If the length is set to a value that is larger than the current length, Flash Player fills the right side with zeros.

If the length is set to a value that is smaller than the current length, the array is truncated.

]]>
Use the bytesAvailable property in conjunction with the read methods each time you access a ByteArray object to ensure that you are reading valid data.

]]>
defaultObjectEncoding. The defaultObjectEncoding property is initialized to ObjectEncoding.AMF3.

When an object is written to or read from binary data, the objectEncoding value is used to determine whether the ActionScript 3.0, ActionScript2.0, or ActionScript 1.0 format should be used. The value is a constant from the ObjectEncoding class.

]]>
start() method to start a timer. Add an event listener for the timer event to set up code to be run on the timer interval.

You can create Timer objects to run once or repeat at specified intervals to execute code on a schedule. Depending on the SWF file's framerate or Flash Player's environment (available memory and other factors), Flash Player may dispatch events at slightly offset intervals. For example, if a SWF file is set to play at 10 frames per second [fps], which is 100 millisecond intervals, but your timer is set to fire an event at 80 milliseconds, Flash Player will fire the event close to the 100 millisecond interval. Memory-intensive scripts may also offset the events.

]]>
/** * @exampleText The following example uses the class <code>TimerExample</code> to show how a * listener method <code>timerHandler()</code> can be set to listen for a new TimerEvent * to be dispatched. The timer is started when <code>start()</code> is called, and after that point, * the timer events are dispatched. */ package { import flash.utils.Timer; import flash.events.TimerEvent; import flash.display.Sprite; public class TimerExample extends Sprite { public function TimerExample() { var myTimer:Timer = new Timer(1000, 2); myTimer.addEventListener("timer", timerHandler); myTimer.start(); } public function timerHandler(event:TimerEvent):void { trace("timerHandler: " + event); } } } Timer.repeatCount. ]]> Timer.repeatCount.]]> type property of a timerComplete event object.

This event has the following properties:

PropertyValue
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
currentTargetThe object that is actively processing the Event object with an event listener.
targetThe Timer object that has completed its requests.
]]>
Timer.delay property. ]]> Timer.delay property.]]> type property of a timer event object.

This event has the following properties:

PropertyValue
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
currentTargetThe object that is actively processing the Event object with an event listener.
targetThe Timer object that has reached its interval.
]]>
delay and repeatCount states.

The timer does not start automatically; you must call the start() method to start it.

]]>
delay and repeatCount states.]]> /** * @exampleText In the following example, the user is given 90 seconds to write * a response in an input text field. Also, every 30 seconds, a status * message lets the user know how many seconds are left. * * <p>A Timer object is created that starts in 30 seconds (delay is set to 30000 * milliseconds) and repeats three times, for a total of 90 seconds. (The timer * stops after the third time.)</p> * * <p>Two event listeners are added for the <code>myTimer</code> timer. The first is * triggered by the <code>TimerEvent.TIMER</code> event, which occurs every time * the timer is started. The <code>timerHandler()</code> method changes * the text for the <code>statusTextField</code> text field to reflect the seconds * remaining. </p> * <p><strong>Note:</strong> The Timer class keeps track of the number of times it has to start * (<code>repeats</code>) by increasing the number in the <code>currentCount</code> property.)</p> * * <p>After the timer is called for the last time, the <code>TimerEvent.TIMER_COMPLETE</code> * event is dispatched and the <code>completeHandler()</code> method is called. * The <code>completeHandler()</code> method changes the type of the <code>inputTextField</code> text field * from <code>INPUT</code> to <code>DYNAMIC</code>, which means the user can no * longer enter or change text.</p> * */ package { import flash.display.Sprite; import flash.text.TextField; import flash.text.TextFieldType; import flash.text.TextFieldAutoSize; import flash.utils.Timer; import flash.events.TimerEvent; import flash.events.Event; public class Timer_constructorExample extends Sprite { private var statusTextField:TextField = new TextField(); private var inputTextField:TextField = new TextField(); private var delay:uint = 30000; private var repeat:uint = 3; private var myTimer:Timer = new Timer(delay, repeat); public function Timer_constructorExample() { inputTextField.x = 10; inputTextField.y = 10; inputTextField.border = true; inputTextField.background = true; inputTextField.height = 200; inputTextField.width = 200; inputTextField.multiline = true; inputTextField.wordWrap = true; inputTextField.type = TextFieldType.INPUT; statusTextField.x = 10; statusTextField.y = 220; statusTextField.background = true; statusTextField.autoSize = TextFieldAutoSize.LEFT; myTimer.start(); statusTextField.text = "You have " + ((delay * repeat) / 1000) + " seconds to write your response."; myTimer.addEventListener(TimerEvent.TIMER, timerHandler); myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, completeHandler); addChild(inputTextField); addChild(statusTextField); } private function timerHandler(e:TimerEvent):void{ repeat--; statusTextField.text = ((delay * repeat) / 1000) + " seconds left."; } private function completeHandler(e:TimerEvent):void { statusTextField.text = "Times Up."; inputTextField.type = TextFieldType.DYNAMIC; } } }
currentCount property back to 0, like the reset button of a stopwatch. Then, when start() is called, the timer instance runs for the specified number of repetitions, as set by the repeatCount value. ]]> currentCount property back to 0, like the reset button of a stopwatch.]]> start() is called after stop(), the timer instance runs for the remaining number of repetitions, as set by the repeatCount property. ]]> repeatCount iteration. ]]> stop() method is invoked or the program stops. If the repeat count is nonzero, the timer runs the specified number of times. If repeatCount is set to a total that is the same or less then currentCount the timer stops and will not fire again. ]]> true if the timer is running, otherwise false. ]]> true if the timer is running, otherwise false.]]>
reflection for the ActionScript language.

If the value parameter is an instance of a type, the returned XML object includes all the instance properties of that type, but does not include any static properties. You can check for this condition when you parse the XML object by examining the value of the <type> tag's isStatic attribute, which is false when the value parameter is an instance of a type.

To obtain the static properties of a type, pass the type itself for the value parameter. The returned XML object includes not only the type's static properties, but also all of its instance properties. The instance properties are nested inside a tag named <factory> to distinguish them from the static properties. In this case, the isStatic attribute of the <type> tag is true.

Note: If you need only to traverse an object's inheritance hierarchy and do not need the other information provided by describeType(), use the getQualifiedClassName() and getQualifiedSuperclassName() functions instead.

The following table describes some of the tags and attributes of the XML object generated by describeType():

TagAttributeDescription
<type> The root tag of the XML object.
 nameThe name of the ActionScript object's data type.
 baseThe immediate superclass of the ActionScript object's defining class. If the ActionScript object is a class object, the value is Class.
 isDynamictrue if the ActionScript object's defining class is dynamic; false otherwise. If the ActionScript object is a class object, the value is true because the Class class is dynamic.
 isFinaltrue if the ActionScript object's defining class is final; false otherwise.
 isStatictrue if the ActionScript object is a class object or constructor function; false otherwise. This attribute is named isStatic because if it is true, any tags that are not nested inside the factory tag are static.
<extendsClass> There is a separate extendsClass tag for each superclass of the ActionScript object's defining class.
 typeThe name of a superclass that the ActionScript object's defining class extends.
<implementsInterface> There is a separate implementsInterface tag for each interface implemented by the ActionScript object's defining class or any of its superclasses.
 typeThe name of an interface that the ActionScript object's defining class implements.
<accessor> An accessor is a property defined by getter and setter functions.
 nameThe name of the accessor.
 accessThe access rights of the property. Possible values include readonly, writeonly, and readwrite.
 typeThe data type of the property.
 declaredByThe class that contains the associated getter or setter functions.
<constant> A constant is a property defined with the const statement.
 nameThe name of the constant.
 typeThe data type of the constant.
<method> A method is a function declared as part of a class definition.
 nameThe name of the method.
 declaredByThe class that contains the method definition.
 returnTypeThe data type of the method's return value.
<parameter> There is a separate parameter tag for each parameter that a method defines. This tag is always nested inside a <method> tag.
 indexA number corresponding to the order in which the parameter appears in the method's parameter list. The first parameter has a value of 1.
 typeThe data type of the parameter.
 optionaltrue if the parameter is optional; false otherwise.
<variable> A variable is a property defined with the var statement.
 nameThe name of the variable.
 typeThe data type of the variable.
<factory> If the ActionScript object is a class object or constructor function, all instance properties and methods are nested inside this tag. If the isStatic attribute of the <type> tag is true, all properties and methods that are not nested within the <factory> tag are static. This tag appears only if the ActionScript object is a class object or constructor function.
]]>
  • The class of the object
  • The attributes of the class
  • The inheritance tree from the class to its base classes
  • The interfaces implemented by the class
  • The declared instance properties of the class
  • The declared static properties of the class
  • The instance methods of the class
  • The static methods of the class
  • For each method of the class, the name, number of parameters, return type, and parameter types
  • Note: describeType() only shows public properties and methods, and will not show properties and methods that are private, package internal or in custom namespaces.

    ]]>
    package { import flash.display.Sprite; import flash.utils.describeType; public class DescribeTypeExample extends Sprite { public function DescribeTypeExample() { var child:Sprite = new Sprite(); var description:XML = describeType(child); trace(description..accessor.@name.toXMLString()); } } }
    name parameter. ]]> name parameter.]]> name parameter. ]]> /** * @exampleText The following example uses the class <code>GetDefinitionByNameExample</code> to * create an orange square on the stage. This is accomplished using the following steps: * <ol> * <li>Variables for the background color of orange and size of 80 pixels are declared, * which will later be used in drawing the square.</li> * <li>Within the constructor, a variable <code>ClassReference</code> of type Class is * assigned to Sprite.</li> * <li>An instance of ClassReference called <code>instance</code> is instantiated.</li> * <li>Since <code>instance</code> is, by reference, a Sprite object, a square can be * drawn and added to the display list using the methods available to Sprite.</li> * </ol> */ package { import flash.display.DisplayObject; import flash.display.Sprite; import flash.utils.getDefinitionByName; public class GetDefinitionByNameExample extends Sprite { private var bgColor:uint = 0xFFCC00; private var size:uint = 80; public function GetDefinitionByNameExample() { var ClassReference:Class = getDefinitionByName("flash.display.Sprite") as Class; var instance:Object = new ClassReference(); instance.graphics.beginFill(bgColor); instance.graphics.drawRect(0, 0, size, size); instance.graphics.endFill(); addChild(DisplayObject(instance)); } } } value parameter. This function provides a quicker way of retrieving the base class name than describeType(), but also doesn't provide all the information describeType() does.

    After you retrieve the name of a class with this function, you can convert the class name to a class reference with the getDefinitionByName() function.

    Note: This function restricts itself to instance hierarchies, whereas the describeType() function uses class object hierarchies if the value parameter is a data type. Calling describeType() on a data type returns the superclass based on the class object hierarchy, in which all class objects inherit from Class. The getQualifiedSuperclassName() function, however, ignores the class object hierarchy and returns the superclass based on the more familiar instance hierarchy. For example, calling getQualifiedSuperclassName(String) returns Object although technically the String class object inherits from Class. In other words, the results are the same whether you use an instance of a type or the type itself.

    ]]>
    value parameter.]]> null if none exists. ]]>
    /** * @exampleText The following example uses the class <code>GetTimerExample</code> to get and print the * number of milliseconds since the Flash Player started playing. */ package { import flash.utils.getTimer; import flash.display.Sprite; public class GetTimerExample extends Sprite { public function GetTimerExample() { var duration:uint = getTimer(); trace("duration: " + duration); } } } Shift-JIS will only be escaped and unescaped properly on an OS using a Japanese default code page. ]]> true, the escaped string is encoded in the system code page. If System.useCodePage is false, the escaped string is encoded in UTF-8. For example, the input string "Crüe" will be escaped as "Cr%C3%BCe" on all systems if System.useCodePage is false. If system.useCodePage is true, and the system uses a Latin code page, "Crüe" will be escaped as "Cr%FCe". If the system uses a non Latin code page that does not contain the letter 'ü' the result will probably be "Cr?e". ]]> Shift-JIS will only be escaped and unescaped properly on an OS using a Japanese default code page. ]]> true, the escaped string is decoded from the system code page. If System.useCodePage is false, the escaped string is decoded from UTF-8. For example, if the input string is "Cr%C3%BCe" and System.useCodePage is false, the result will be "Crüe" on all systems. If System.useCodePage is true and the input string is "Cr%FCe", and the system uses a Latin code page, the result will also be "Crüe". Unescaping "Cr%C3%BCe" with System.useCodePage set to true will produce different undesired results on different systems, such as "Crüe" on a Latin system. Similarly, unescaping "Cr%FCe" with System.useCodePage set to false could produce "Cre" or "Cr?e" or other variations depending on the code page of the system. ]]> Instead of using the setInterval() method, consider creating a Timer object, with the specified interval, using 0 as the repeatCount parameter (which sets the timer to repeat indefinitely).

    If you intend to use the clearInterval() method to cancel the setInterval() call, be sure to assign the setInterval() call to a variable (which the setInterval() method will later reference), as in the following:

    ]]>
    functionName, not functionName() or functionName(param). ]]> /** * @exampleText The following example uses the <code>setInterval()</code> method to create a timed * interval, calling the <code>myRepeatingFunction()</code> method after regular intervals of one * second. */ package { import flash.display.Sprite; import flash.utils.*; public class SetIntervalExample extends Sprite { private var intervalDuration:Number = 1000; // duration between intervals, in milliseconds public function SetIntervalExample() { var intervalId:uint = setInterval(myRepeatingFunction, intervalDuration, "Hello", "World"); } public function myRepeatingFunction():void { trace(arguments[0] + " " + arguments[1]); } } }
    Instead of using this method, consider creating a Timer object, with the specified interval, using 1 as the repeatCount parameter (which sets the timer to run only once).

    If you intend to use the clearTimeout() method to cancel the setTimeout() call, be sure to assign the setTimeout() call to a variable (which the clearTimeout() method will later reference)

    ]]>
    functionName, not functionName() or functionName(param). ]]> /** * @exampleText The following example uses the <code>setTimeout()</code> method to call another * method following a specified delay period. */ package { import flash.display.Sprite; import flash.utils.*; public class SetTimeoutExample extends Sprite { private var delay:Number = 1000; // delay before calling myDelayedFunction public function SetTimeoutExample() { var intervalId:uint = setTimeout(myDelayedFunction, delay, "Hello", "World"); } public function myDelayedFunction():void { trace(arguments[0] + " " + arguments[1]); } } }
    setInterval() call. ]]> setInterval() call.]]> setInterval() call, which you set to a variable, as in the following: ]]> /** * @exampleText The following example uses the <code>setInterval()</code> method to create a timed * interval, calling the <code>myRepeatingFunction()</code> method after regular intervals of one * second. * * <p>Each call of the <code>myRepeatingFunction</code> method increments the <code>counter</code> * property, and when it equals the <code>stopCount</code> property, the <code>clearInterval() * </code> method is called with the property <code>intervalId</code> which is a reference id to * the interval that was created earlier.</p> */ package { import flash.display.Sprite; import flash.utils.*; public class ClearIntervalExample extends Sprite { private var intervalDuration:Number = 1000; // duration between intervals, in milliseconds private var intervalId:uint; private var counter:uint = 0; private var stopCount:uint = 3; public function ClearIntervalExample() { intervalId = setInterval(myRepeatingFunction, intervalDuration, "Hello", "World"); } public function myRepeatingFunction():void { trace(arguments[0] + " " + arguments[1]); counter++; if(counter == stopCount) { trace("Clearing Interval"); clearInterval(intervalId); } } } } setTimeout() call. ]]> setTimeout() call.]]> setTimeout() call, which you set to a variable, as in the following: ]]> /** * @exampleText The following example uses the <code>setTimeout()</code> method to call another * method following a specified delay period. * * <p>A loop is created to count to one million. If the computer can process this request faster * than a second can expire, <code>clearTimeout()</code> will remove the <code>setTimeout()</code> * request, and <code>myDelayedFunction()</code> will not be called.</p> */ package { import flash.display.Sprite; import flash.utils.*; public class ClearTimeoutExample extends Sprite { private var delay:Number = 1000; // delay before calling myDelayedFunction private var intervalId:uint; private var count:uint = 1000000; public function ClearTimeoutExample() { intervalId = setTimeout(myDelayedFunction, delay); startCounting(); } public function startCounting():void { var i:uint = 0; do { if(i == count-1) { clearTimeout(intervalId); trace("Your computer can count to " + count + " in less than " + delay/1000 + " seconds."); } i++; } while(i < count) } public function myDelayedFunction():void { trace("Time expired."); } } }
    easeOut() method starts the bounce motion fast and then decelerates motion as it executes. ]]> easeOut() method starts the bounce motion fast and then decelerates motion as it executes.]]> easeIn() method starts the bounce motion slowly and then accelerates motion as it executes. ]]> easeIn() method starts the bounce motion slowly and then accelerates motion as it executes.]]> easeInOut() method combines the motion of the easeIn() and easeOut() methods to start the bounce motion slowly, accelerate motion, then decelerate. ]]> easeInOut() method combines the motion of the easeIn() and easeOut() methods to start the bounce motion slowly, accelerate motion, then decelerate.]]> easeIn, easeOut and so on, are provided in the interest of polymorphism. ]]> easeNone() method defines a constant motion with no acceleration. ]]> easeNone() method defines a constant motion with no acceleration.]]> easeIn() method defines a constant motion with no acceleration. ]]> easeIn() method defines a constant motion with no acceleration.]]> easeOut() method defines a constant motion with no acceleration. ]]> easeOut() method defines a constant motion with no acceleration.]]> easeInOut() method defines a constant motion with no acceleration. ]]> easeInOut() method defines a constant motion with no acceleration.]]> easeIn() method starts the motion by backtracking and then reversing direction and moving toward the target. ]]> easeIn() method starts the motion by backtracking and then reversing direction and moving toward the target.]]> easeOut() method starts the motion by moving towards the target, overshooting it slightly, and then reversing direction back toward the target. ]]> easeOut() method starts the motion by moving towards the target, overshooting it slightly, and then reversing direction back toward the target.]]> easeInOut() method combines the motion of the easeIn() and easeOut() methods to start the motion by backtracking, then reversing direction and moving toward the target, overshooting the target slightly, reversing direction again, and then moving back toward the target. ]]> easeInOut() method combines the motion of the easeIn() and easeOut() methods to start the motion by backtracking, then reversing direction and moving toward the target, overshooting the target slightly, reversing direction again, and then moving back toward the target.]]>