MACROMEDIA COLDFUSION MX 7.0.2-USING COLDFUSION MX WITH FLEX 2 Guia do Utilizador Página 146

  • Descarregar
  • Adicionar aos meus manuais
  • Imprimir
  • Página
    / 256
  • Índice
  • MARCADORES
  • Avaliado. / 5. Com base em avaliações de clientes
Vista de página 145
146 Use an Event Listener
11. Switch to Source mode and examine the code generated by Flex Builder.
Your code should look as follows (your coordinate values may vary):
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:Panel x="20" y="20" width="450" height="150" layout="absolute"
title="Currency Converter">
<mx:Label x="25" y="37" text="Price in Dollars"/>
<mx:Label x="120" y="65" id="lblResults"/>
<mx:TextInput x="120" y="35" id="txtPrice"/>
<mx:Button x="290" y="35" label="Convert to Yen" id="btnConvert"/
>
</mx:Panel>
</mx:Application>
12.
Save your file.
Write an event listener
Next, you write an event listener for the Convert to Yen button. You want the listener to
consist of an ActionScript function that can calculate and display a specified dollar price in
yen.
1. Switch to Source mode and place the insertion point immediately after the opening
<mx:Application> tag.
2. Start typing <mx:Script> until the full tag is selected in the code hints, press Enter to insert
the tag in your code, and then type the closing angle bracket (>) to complete the tag.
Flex Builder enters an
<mx:Script> script block that also includes a CDATA construct.
3. Enter or paste the following code in the CDATA construct:
public function convertCurrency():void {
var rate:Number = 120;
var price:Number = Number(txtPrice.text);
if (isNaN(price)) {
lblResults.text = "Please enter a valid price.";
} else {
price = price * rate;
lblResults.text = "Price in Yen: " + String(price);
}
}
NOTE
When using an <mx:Script> script block, you should wrap the contents in a CDATA
construct. This prevents the compiler from interpreting the contents of the script
block as XML, and allows the ActionScript to be properly generated.
Vista de página 145
1 2 ... 141 142 143 144 145 146 147 148 149 150 151 ... 255 256

Comentários a estes Manuais

Sem comentários