addProperty (Object.addProperty method)
public addProperty(name:String, getter:Function, setter:Function) : Boolean
Creates a getter/setter property. When Flash reads a getter/setter property, it invokes the
function, and the function's return value becomes the value of
getter/setter property, it invokes the
a property with the given name already exists, the new property overwrites it.
A "get" function is a function with no parameters. Its return value can be of any type. Its type
can change between invocations. The return value is treated as the current value of the
property.
A "set" function is a function that takes one parameter, which is the new value of the property.
For example, if property
parameter
of type number. The return value of the set function is ignored.
1
You can add getter/setter properties to prototype objects. If you add a getter/setter property to
a prototype object, all object instances that inherit the prototype object inherit the getter/
setter property. This makes it possible to add a getter/setter property in one location, the
prototype object, and have it propagate to all instances of a class (similar to adding methods to
prototype objects). If a get/set function is invoked for a getter/setter property in an inherited
prototype object, the reference passed to the get/set function is the originally referenced
object--not the prototype object.
If invoked incorrectly,
describes errors that can occur:
Error condition
is not a valid property name; for example,
name
an empty string.
is not a valid function object.
getter
is not a valid function object.
setter
Availability: ActionScript 1.0; Flash Player 6 - In ActionScript 2.0 classes, you can use get or
set instead of this method.
Parameters
- A string; the name of the object property to create.
name:String
- The function that is invoked to retrieve the value of the property; this
getter:Function
parameter is a Function object.
992
ActionScript classes
function and passes it the new value as a parameter. If
set
is assigned by the statement
x
Object.addProperty()
. When Flash writes a
name
, the set function is passed the
x = 1
can fail with an error. The following table
What happens
Returns
and the property is not added.
false
Returns
and the property is not added.
false
Returns
and the property is not added.
false
get
Need help?
Do you have a question about the FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE and is the answer not in the manual?