EasyManua.ls Logo

MACROMEDIA FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE - Page 993

MACROMEDIA FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE
1378 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
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.bookcount+" copies of "+myBook.bookname);
// output: You ordered 5 copies of Catcher in the Rye

Table of Contents

Related product manuals