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> 

이것은 BMI 계산기의 GUI입니다. 나는 플래시 빌더를 사용하는 기본을 가지고 있지 않다. 누구든지 텍스트 입력 내부에서 사용자가 입력 한 데이터를 사용하여 계산에 사용하고 표시하는 방법을 가르쳐 줄 수 있습니까? 덕분에플렉스 - Flash Builder에서 계산하는 방법

답변

0

먼저 당신은 그래서 당신의 calculate_clickHandler 방법은 버튼 클릭에 호출됩니다 귀하의 버튼에 클릭 핸들러를 할당합니다

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

그런 다음 당신은 당신의 계산을하고 myresult 라벨에 결과를 전달합니다

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; 
} 

그리고 아마도 뒤로 버튼을 클릭 할 때 popView()를 원할 것입니다. 이렇게하면 현재보기가 제거되고 마지막보기로 돌아갑니다. 푸시()는 다른보기를 추가합니다 :

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

TQ 내가 그것을 밖으로 시도 할 것이다. 나는 그것이 성공하면 여기에 그것을 알릴 것이다 .. 1 가지 더. 나는 APK 파일로 프로젝트를 변환했지만 안드로이드 전화에 설치하면 app/apk가 실행되지 않습니다. 어떤 해결책? –

0

이 시도 : 답장에 대한

<?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

녀석. 계산에서 소수점을 제거하는 방법 –

+0

const BMI : 숫자를 const BMI : int로 대체하여 사용하십시오. – gbdcool

관련 문제