Object
993
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.
function Book() {
this.setQuantity = function(numBooks:Number):Void {
this.books = numBooks;
};
this.getQuantity = function():Number {
return this.books;
};
this.getTitle = function():String {
return "Catcher in the Rye";
};
this.addProperty("bookcount", this.getQuantity, this.setQuantity);
this.addProperty("bookname", this.getTitle, null);
}
var myBook = new Book();
myBook.bookcount = 5;
trace("You ordered "+myBook.bo" copies of "+myBook.bookname);
// output: You ordered 5 copies of Catcher in the Rye
Содержание FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE
Страница 1: ...ActionScript 2 0 Language Reference ...
Страница 1352: ...1352 ActionScript classes ...