
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
The CurrencyConverter Class
|
299
For the sake of this example, the exchange rates in our application are permanently
set in class properties. In a real currency converter, they’d most likely be retrieved at
runtime from a dynamic, server-side source, as described in Flash Remoting: The
Definitive Guide by Tom Muck (O’Reilly).
Notice that not all of our user interface components are stored in instance proper-
ties. After creation, some components (e.g., the Label components) need not be used
again and, hence, are not stored in instance properties. When creating a component,
we store a reference to it only if another method in the class needs to manipulate it
later in the application.
The main( ) method
The currency converter application’s startup method is CurrencyConverter.main( ):
public static function main (target:MovieClip, depth:Number,
x:Number, y:Number):Void {
var converter:CurrencyConverter = new CurrencyConverter(target, depth,
x, y);
}
The main( ) method is a class method (i.e., declared static) because it is invoked once
for the entire application and is not associated with a particular instance. The main( )
method uses a common Java convention to set things in motion: it creates an
instance of the application’s primary class, CurrencyConverter, and stores that
instance in