MACROMEDIA COLDFUSION MX 7.0.2-USING COLDFUSION MX WITH FLEX 2 Guida Utente Pagina 149

  • Scaricare
  • Aggiungi ai miei manuali
  • Stampa
  • Pagina
    / 256
  • Indice
  • SEGNALIBRI
  • Valutato. / 5. Basato su recensioni clienti
Vedere la pagina 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();"
Vedere la pagina 148
1 2 ... 144 145 146 147 148 149 150 151 152 153 154 ... 255 256

Commenti su questo manuale

Nessun commento