MACROMEDIA COLDFUSION MX 7.0.2-USING COLDFUSION MX WITH FLEX 2 Guide de l'utilisateur Page 149

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 256
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 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();"
Vue de la page 148
1 2 ... 144 145 146 147 148 149 150 151 152 153 154 ... 255 256

Commentaires sur ces manuels

Pas de commentaire