
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
300
|
Chapter 12: Using Components with ActionScript 2.0
The Class Constructor
The CurrencyConverter class constructor is straightforward. It simply invokes
buildConverter( ), which creates our application’s user interface:
public function CurrencyConverter (target:MovieClip, depth:Number,
x:Number, y:Number) {
buildConverter(target, depth, x, y);
}
Notice that, like the main( ) method, the constructor passes on its arguments to
another section of the program—in this case the buildConverter( ) method, which
uses the arguments to create the application’s interface.
Creating the User Interface
As we’ve just learned, the currency converter interface is created by the
buildConverter( ) method. To create the interface, buildConverter( ) instantiates user
interface components and defines event handlers that dictate the interface’s behavior.
You should already have skimmed the full listing for buildConverter( ) earlier in
Example 12-1. Now let’s study the method line by line.
The first line of code in buildConverter( ) may be unfamiliar to some programmers—
it stores a reference to the current object in a local variable named
thisConverter:
var thisConverter:CurrencyConverter = this;
Storing the current object in a local variable adds it to the buildConverter( ) method’s
scope chain. This not only ...