
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
OOP Quick Reference
|
315
The following code adds a scrollToBottom( ) method to the TextField class:
TextField.prototype.scrollToBottom = function ( ) {
this.scroll = this.maxscroll;
};
The following code creates a subclass of the XML class:
function CustomXML (src) {
super(src);
}
CustomXML.prototype = new XML( );
Some built-in classes actually require the execution of their constructor function as
part of the setup for new objects. When in doubt, always invoke the superclass con-
structor as shown in our previous examples. Note that not all built-in classes can be
subclassed, because some built-in classes (e.g., TextField, Button) are tied to physical
objects on screen. See each class entry in the Language Reference for details.
Many, many more examples of extending the built-in classes and objects can be
found on the developer community site [PROTO]type:
http://www.layer51.com/proto/
OOP Quick Reference
We’ve covered a lot of material in this chapter. For review and reference, here’s a
quick-and-dirty overview of OOP techniques in ActionScript. At the end, you’ll find
a template for creating a new OOP application.
To create a class:
function ClassName (param1, param2) {
// ...constructor code goes here...
}
To create instance properties for a class:
function ClassName (param1, param2) {
// ...