800
Object-Oriented Programming with ActionScript 1.0
Adding getter/setter properties to objects
in ActionScript 1.0
You can create getter/setter properties for an object using the
Object.addProperty()
method.
A
getter 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
setter function
is a function that takes one parameter, which is the new value of the property.
For instance, if property x is assigned by the statement x = 1, the setter function is passed the
parameter 1 of type Number. The return value of the setter function is ignored.
When Flash reads a getter/setter property, it invokes the getter function, and the function’s
return value becomes a value of
prop
. When Flash writes a getter/setter property, it invokes
the setter function and passes it the new value as a parameter. If a property with the given
name already exists, the new property overwrites it.
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. You can 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 getter/setter function is invoked for a getter/setter property in an inherited prototype object,
the reference passed to the getter/setter function is the originally referenced object, not the
prototype object.
The Debug > List Variables command in test mode supports getter/setter properties that you
add to objects using
Object.addProperty()
. Properties that you add to an object in this way
appear with other properties of the object in the Output panel. Getter/setter properties are
identified in the Output panel with the prefix
[getter/setter]
. For more information on
the List Variables command, see
“Using the Output panel” on page 724
.
NO
T
E
Many Flash users can greatly benefit from using ActionScript 2.0, especially with
complex applications. For information on using ActionScript 2.0, see
Chapter 7,
“Classes,” on page 225
.
Summary of Contents for FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Page 1: ...Learning ActionScript 2 0 in Flash...
Page 8: ...8 Contents...
Page 18: ...18 Introduction...
Page 30: ...30 What s New in Flash 8 ActionScript...
Page 66: ...66 Writing and Editing ActionScript 2 0...
Page 328: ...328 Interfaces...
Page 350: ...350 Handling Events...
Page 590: ...590 Creating Interaction with ActionScript...
Page 710: ...710 Understanding Security...
Page 730: ...730 Debugging Applications...
Page 780: ...780 Deprecated Flash 4 operators...
Page 830: ...830 Index...