MACROMEDIA FLEX-GETTING STARTED WITH FLEX Getting Started page 56

Table of Contents

Advertisement

</mx:HBox>
</mx:Panel>
</mx:Application>
The sample3script.as ActionScript file contains the following code:
function calculate() {
celsius.text=(farenheit.text-32)/1.8;
}
One codeless MXML document and one ActionScript component
The following example uses an ActionScript class as a controller component. The ActionScript
component is declared in the application using a custom MXML tag. To use the TempConverter
component in an application, you call its
of the
<mx:Application>
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"
initialize="converter.setupListener()">
<local:TempConverter id="converter" xmlns:local="*"/>
<mx:Panel title="My Application" marginTop="10" marginBottom="10"
marginLeft="10" marginRight="10" >
<mx:HBox>
<mx:Label text="Temperature in Farenheit:" />
<mx:TextInput id="farenheit" width="120" />
<mx:Button id="myButton" label="Convert" />
<mx:Label text="Temperature in Celsius:" />
<mx:Label id="celsius" width="120" fontSize="24" />
</mx:HBox>
</mx:Panel>
</mx:Application>
The TempConverter.as ActionScript class contains the following code:
class TempConverter implements mx.core.MXMLObject{
public var view;
function initialized(doc : Object, id : String) : Void {
view = doc;
}
function setupListener() : Void {
view.myButton.addEventListener("click", this);
}
function click(event) {
view.celsius.text=(view.farenheit.text-32)/1.8;
}
}
TempConverter is an MXMLObject and the compiler calls the
instances of MXMLObject.
56
Chapter 3: Using ActionScript
setupListener()
tag, as the following code shows:
method in the
initialize
method on all
initialized()
property

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLEX-GETTING STARTED WITH FLEX and is the answer not in the manual?

Questions and answers

This manual is also suitable for:

Flex

Table of Contents