The following example shows how to use the implicit getter and setter functions available in
ActionScript 2.0. Rather than defining the
define the
class in an external file named Book.as. The following code must be in a
Book
separate external file named Book.as that contains only this class definition and resides within
the Flash application's classpath:
class Book {
var books:Number;
function set bookcount(numBooks:Number):Void {
this.books = numBooks;
}
function get bookcount():Number {
return this.books;
}
function get bookname():String {
return "Catcher in the Rye";
}
}
The following code can then be placed in a FLA file and will function the same way as it does
in the previous examples:
var myBook:Book = new Book();
myBook.bookcount = 5;
trace("You ordered "+myBook.bookcount+" copies of "+myBook.bookname);
See also
,
get statement
set statement
constructor (Object.constructor property)
public constructor :
Reference to the constructor function for a given object instance. The
is automatically assigned to all objects when they are created using the constructor for the
Object class.
Availability: ActionScript 1.0; Flash Lite 2.0
Example
The following example is a reference to the constructor function for the
var my_str:String = new String("sven");
trace(my_str.constructor == String); //output: true
554
ActionScript classes
Book
Object
function and editing
, you
Book.prototype
property
constructor
object.
myObject
Need help?
Do you have a question about the FLASHLITE2 ACTIONSCRIPT-LANGUAGE and is the answer not in the manual?
Questions and answers