2016-09-21 2 views
-1
<?xml version="1.0" encoding="utf-8"?> 
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" title="BMI Calculator"> 

<fx:Script> 
    <![CDATA[ 
     protected function calculate_clickHandler(event:MouseEvent):void 
     { 
      // TODO Auto-generated method stub 

     } 
    ]]> 
</fx:Script> 

<fx:Declarations> 
    <!-- Place non-visual elements (e.g., services, value objects) here --> 
</fx:Declarations> 
<s:actionContent> 
    <s:Button label="Back" click="navigator.pushView(MainHomeView)" styleName="back"/> 
</s:actionContent> 
<s:Label x="33" y="61" fontSize="30" text="Weight(kg) :"/> 
<s:Label x="34" y="140" fontSize="30" text="Height(cm) :"/> 
<s:TextInput id="mywieght" x="216" y="40" width="228" prompt="0.0kg" textAlign="right"/> 
<s:TextInput id="myheight" x="216" y="119" width="228" prompt="0.0cm" textAlign="right"/> 
<s:Button id="calculation" x="31" y="260" width="413" label="Calculate" fontSize="36" 
      fontStyle="italic"/> 
<s:Label id="myresult" left="31" right="36" height="146" fontSize="72" fontStyle="normal" 
     fontWeight="bold" text="0.0" textAlign="center" verticalAlign="middle" 
     verticalCenter="99"/> 
</s:View> 

Ceci est le gui pour un calculateur d'IMC. Je n'ai pas vraiment la base de l'utilisation de Flash Builder. Quelqu'un peut-il m'apprendre comment utiliser les données entrées par l'utilisateur à l'intérieur de l'entrée de texte, puis l'utiliser pour le calcul et l'afficher? grâceFlex - Comment faire un calcul dans Flash Builder

Répondre

0

D'abord, vous assigner un gestionnaire de clic à votre bouton afin que votre méthode de calculate_clickHandler sera appelé sur le bouton clic:

<s:Button id="calculation" x="31" y="260" width="413" label="Calculate" fontSize="36" fontStyle="italic" click="calculate_clickHandler(event)"/> 

Alors vous faites vos calculs et passer votre résultat au myResult Label:

protected function calculate_clickHandler(event:MouseEvent):void 
{ 
    var height:Number = Number(myheight.text); 
    var weight:Number = Number(mywieght.text); // you have a typo here, wiegth instead of weight ;) 

    myresult.text = height * weight; 
} 

Et vous voulez probablement un clic popView() sur le bouton de retour. Cela supprimera la vue actuelle et reviendra à votre dernière vue. push() ajoutera une autre vue:

<s:Button label="Back" click="navigator.popView()" styleName="back"/> 
+0

TQ pour les réponses je vais essayer. Je vais l'informer ici si elle réussit .. 1 chose de plus. J'ai converti le projet dans un fichier apk mais lorsqu'il est installé dans un téléphone Android, l'app/apk ne démarre pas. Toute solution? –

0

Essayez ceci:

<?xml version="1.0"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"> 
<fx:Script> 
<![CDATA[ 
    protected function calculate_clickHandler(event:MouseEvent):void 
    { 
     // TODO Auto-generated method stub 
     const myWeightInKG:Number = Number(myWeight.text); 
     const myHeightInMeter:Number = Number(myHeight.text) * 0.01; 
     const BMI:Number = myWeightInKG/(myHeightInMeter * myHeightInMeter); 
     const BMI_withOneDecimalPlace:Number = int(BMI * 10)/10; 
     myResult.text = BMI_withOneDecimalPlace.toString(); 
    } 
    ]]> 
</fx:Script> 

<fx:Declarations> 
    <!-- Place non-visual elements (e.g., services, value objects) here --> 
</fx:Declarations> 

<s:Label x="33" y="61" fontSize="30" text="Weight(kg) :"/> 
<s:Label x="34" y="140" fontSize="30" text="Height(cm) :"/> 
<s:TextInput id="myWeight" x="216" y="40" width="228" prompt="Weight in Kg(e.g. 56)" textAlign="right"/> 
<s:TextInput id="myHeight" x="216" y="119" width="228" prompt="Weight in cm(e.g. 157)" textAlign="right"/> 
<s:Button id="calculation" x="31" y="260" width="413" label="Calculate" fontSize="36" 
      fontStyle="italic" click="calculate_clickHandler(event)"/> 
<s:Label id="myResult" left="31" right="36" height="146" fontSize="72" fontStyle="normal" 
     fontWeight="bold" text="0.0" textAlign="center" verticalAlign="middle" 
     verticalCenter="99"/> 
</s:Application> 
+0

les gars. comment puis-je supprimer les points décimaux du calcul –

+0

Remplacer const BMI: Nombre avec const BMI: int et l'utiliser. – gbdcool