576
Chapter 12: ActionScript Dictionary
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 (much like 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 will be the originally referenced object, not the
prototype object.
If invoked incorrectly,
Object.addProperty()
may fail with an error. The following table
describes errors that may occur:
Example
Usage 1: 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
:
function Book() {
this.setQuantity = function(numBooks) {
this.books = numBooks;
}
this.getQuantity = function() {
return this.books;
}
this.getTitle = function() {
return "Catcher in the Rye";
}
this.addProperty("bookcount", this.getQuantity, this.setQuantity);
this.addProperty("bookname", this.getTitle, null);
}
myBook = new Book();
myBook.bookcount = 5;
order = "You ordered " + myBook.boo " copies of " + myBook.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
prop
is not a valid property name; for instance, an
empty string.
Returns
false
and the property is not added.
getFunc
is not a valid function object.
Returns
false
and the property is not added.
setFunc
is not a valid function object.
Returns
false
and the property is not added.
Summary of Contents for FLASH MX 2004 - ACTIONSCRIPT
Page 1: ...ActionScript Reference Guide...
Page 8: ...8 Contents...
Page 12: ......
Page 24: ...24 Chapter 1 What s New in Flash MX 2004 ActionScript...
Page 54: ...54 Chapter 2 ActionScript Basics...
Page 80: ...80 Chapter 3 Writing and Debugging Scripts...
Page 82: ......
Page 110: ...110 Chapter 5 Creating Interaction with ActionScript...
Page 112: ......
Page 120: ...120 Chapter 6 Using the Built In Classes...
Page 176: ......
Page 192: ...192 Chapter 10 Working with External Data...
Page 202: ...202 Chapter 11 Working with External Media...
Page 204: ......
Page 782: ...782 Chapter 12 ActionScript Dictionary...
Page 793: ...Other keys 793 221 222 Key Key code...
Page 794: ...794 Appendix C Keyboard Keys and Key Code Values...
Page 798: ...798 Appendix D Writing Scripts for Earlier Versions of Flash Player...
Page 806: ...806 Appendix E Object Oriented Programming with ActionScript 1...
Page 816: ...816 Index...