
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
200
|
Chapter 6: Inheritance
Here’s how we’d use the TextFieldDeluxe class:
var tfd:TextFieldDeluxe = new TextFieldDeluxe(someClip_mc, "theField", 1,
20, 20, 400, 200);
// Text field displays: Hello world[LINK ADDED HERE]
tfd.htmlText = "Hello world";
trace(tfd.getDepth( )); // Output panel displays: 1
Built-in Classes that Store Function Libraries
Some built-in ActionScript classes are simply collections of class methods and class
properties—the Math, Key, Mouse, Selection, and Stage classes exist merely to store
related functions and variables (e.g., Math.random( ) and
Key.ENTER). Rather than
subclassing these classes, also known as static function libraries, you should distrib-
ute your own static function libraries separately. For example, rather than adding a
factorial( ) method to a subclass of the Math class, you should create a custom class,
say AdvancedMath, to hold your factorial( ) method. The AdvancedMath class need
not (indeed, should not) be related to the Math class via inheritance.
tf = target[name];
}
public static function addLinks (s:String):String {
// The real implementation of link insertion is not shown here.
// Instead, we just add some text to the string, as a proof of concept.
return s + "[LINK ADDED HERE]";
}
public function set htmlText (s:String):Void {
tf.htmlText ...