
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
The CurrencyConverter Class
|
305
We chose this implementation to separate the application’s display layer from its
data layer (which might retrieve conversion rates from a server-side application). An
alternative, less flexible implementation might embed the currency conversion rates
directly in the
data property of each ComboBox item.
The convertButton Button component
We’ve already seen that the user can convert a value simply by pressing the Enter key
while typing in the
input text field. We’ll now add an explicit Convert button to the
application for users who prefer not to use the Enter key.
The
convertButton component is an instance of the mx.controls.Button component
class, not to be confused with the native Button class that represents instances of
Button symbols in a movie. Because we imported the mx.controls.* package earlier,
the compiler knows to treat unqualified references to Button as references to the
mx.controls.Button class.
To create and position the
convertButton component, we use now-familiar techniques:
// Create the Convert button.
var convertButton:Button = converter_mc.createClassObject(Button,
"convertButton",
4);
convertButton.move(currencyPicker.x + currencyPicker.width + 5,
currencyPicker.y);
To specify the text on convertButton, we assign a string to its label ...