User Guide

552 ActionScript classes
If invoked incorrectly, Object.addProperty() can fail with an error. The following table
describes errors that can occur:
Availability: ActionScript 1.0; Flash Lite 2.0 - In ActionScript 2.0 classes, you can use get or
set instead of this method.
Parameters
name:String - A string; the name of the object property to create.
getter:Function - The function that is invoked to retrieve the value of the property; this
parameter is a Function object.
setter:Function - The function that is invoked to set the value of the property; this
parameter is a Function object. If you pass the value
null for this parameter, the property is
read-only.
Returns
Boolean - A Boolean value: true if the property is successfully created; false otherwise.
Example
In the following example, an object has two internal methods,
setQuantity() and
getQuantity(). A property, bookcount, can be used to invoke these methods when it is
either set or retrieved. A third internal method,
getTitle(), returns a read-only value that is
associated with the property
bookname. When a script retrieves the value of
myBook.bookcount, the ActionScript interpreter automatically invokes
myBook.getQuantity(). When a script modifies the value of myBook.bookcount, the
interpreter invokes
myObject.setQuantity(). The bookname property does not specify a
set function, so attempts to modify bookname are ignored.
Error condition What happens
name is not a valid property name; for example,
an empty string.
Returns false and the property is not added.
getter is not a valid function object. Returns false and the property is not added.
setter is not a valid function object. Returns false and the property is not added.