MACROMEDIA FLASH MX 2004-ACTIONSCRIPT LANGUAGE Reference page 663

Actionscript language reference
Table of Contents

Advertisement

Error condition
is not a valid function object.
getFunc
is not a valid function object.
setFunc
Example
In the following example, an object has two internal methods,
. A property,
getQuantity()
set or retrieved. A third internal method,
with the property
bookname
ActionScript interpreter automatically invokes
the value of
myBook.bookcount
property does not specify a
bookname
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
The previous example works, but the properties
instance of the
Book
If there are many properties, such as
great deal of memory. Instead, you can add the properties to
and
bookcount
bookname
that of the code in the example that added
an attempt is made to access either property in a Book instance, the property's absence will cause
the prototype chain to be ascended until the versions defined in
encountered. The following example shows how to add the properties to
function Book() {}
Book.prototype.setQuantity = function(numBooks:Number):Void {
this.books = numBooks;
};
Book.prototype.getQuantity = function():Number {
return this.books;
};
Book.prototype.getTitle = function():String {
return "Catcher in the Rye";
};
, can be used to invoke these methods when it is either
bookcount
getTitle()
. When a script retrieves the value of
, the interpreter invokes
function, so attempts to modify
set
object, which requires having two properties for every instance of the object.
bookcount
properties exist only in one place. The effect, however, is the same as
What happens
Returns
and the property is not added.
false
Returns
and the property is not added.
false
setQuantity()
, returns a read-only value that is associated
myBook.getQuantity()
myObject.setQuantity()
and
bookcount
and
bookname,
Book.prototype
and
bookcount
bookname
and
, the
myBook.bookcount
. When a script modifies
. The
are ignored.
bookname
are added to every
bookname
in a class, they could consume a
so that the
directly to every instance. If
are
Book.prototype
Book.prototype
Object.addProperty()
:
663

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH MX 2004-ACTIONSCRIPT LANGUAGE and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flash mx

Table of Contents