We don’t need anymore to create controls which are internally accessible. We will just create a Button control to convert the temperature, and the label which indicates that the temperature unit of the input field is celsius.

var _btn = new Button("Convert", _input.width);
var celsiusLabel:Label = new Label("celsius");

All controls are built now. To add them at one time into the Popup container we use the addGraphicElements method. The following line of code illustrates this process:

addGraphicElements(_input, celsiusLabel, _btn, _result);

Well, the widget is not so bad, but it is not interactive yet. We must implement a function to convert the temperature. Let's call it convertTemp. The algorithm of the convertTemp function is quite simple. When the user clicks the "convert" button, the program reads the input field value as a Number, and writes the converted value into the result label field.

To add mouse actions, we use the UIMouseEvent class:

import org.flashapi.swing.event.*;

The event model of SPAS 3.0 is exactly the same as the AS3 event model. But it is better to use the SPAS 3.0 integrated tools to manipulate events, than to use an other system. SPAS 3.0 has its own event sub-system to prevent leak of memory due to event management. That's why we use the eventCollector property of the Popup class to register the button event:

eventCollector.addEvent(_btn, UIMouseEvent.CLICK, convertTemp);

When the user clicks the button, it will call the convertTemp function which is based on the algorithm described above:

private function convertTemp(event:UIMouseEvent):void {
var temp:Number = Number(_input.label);
_result.label = String(temp * 1.8 + 32) + " fahrenheit";
}