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

  • Descarregar
  • Adicionar aos meus manuais
  • Imprimir
  • Página
    / 256
  • Índice
  • MARCADORES
  • Avaliado. / 5. Com base em avaliações de clientes
Vista de página 148
Associate the listener with an event with ActionScript 149
4. Enter the following function immediately before the convertCurrency function in the
<mx:Script> tag:
public function createListener():void {
btnConvert.addEventListener(MouseEvent.CLICK, convertCurrency);
}
When the user clicks the btnConvert button, the convertCurrency event listener is
notified that a triggering event has occurred. The listener function performs the currency
calculation and displays the results.
The script block should look as follows:
<mx:Script>
<![CDATA[
import flash.events.MouseEvent;
public function createListener():void {
btnConvert.addEventListener(MouseEvent.CLICK, convertCurrency);
}
public function convertCurrency(e:MouseEvent):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);
}
}
]]>
</mx:Script>
5.
In the <mx:Application> tag, enter the following property so that the
createListener() function is called and the event listener is registered immediately after
the application is created:
creationComplete="createListener();"
Vista de página 148
1 2 ... 144 145 146 147 148 149 150 151 152 153 154 ... 255 256

Comentários a estes Manuais

Sem comentários