主要源码如下
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
width="300" height="230" fontFamily="DingTalkJinBuTi" fontSize="14"
layout="vertical">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.FlexEvent;
[Embed(source="DingTalkJinBuTi-Regular.ttf",fontName="DingTalkJinBuTi",embedAsCFF="false")]
private static var DingTalkJinBuTi:Class;
protected function btnTest_clickHandler(event:MouseEvent):void
{
var _weight:Number = weightInput.value;
var _bodyHeight:Number = bodyHeightInput.value;
var ratio:Number = 1;
switch(genderRadioGroup.selection)
{
case rbFemale:
{
ratio = _weight/((_bodyHeight-70)*0.6);
break;
}
case rbMale:
{
ratio = _weight/((_bodyHeight-80)*0.7);
break;
}
default:
{
Alert.show("请选择性别");
return;
}
}
if(ratio>1.1){
Alert.show("您的身体偏胖");
}else if(ratio<0.9){
Alert.show("您的身体偏瘦");
}else{
Alert.show("您的体重正常");
}
}
]]>
</mx:Script>
<mx:Label fontSize="18" text="健康测试"/>
<mx:HBox width="200" verticalAlign="middle">
<mx:Label text="身高"/>
<mx:NumericStepper id="bodyHeightInput" width="100%" maximum="260" value="170"/>
<mx:Label width="30" text="cm"/>
</mx:HBox>
<mx:HBox width="200" verticalAlign="middle">
<mx:Label text="体重"/>
<mx:NumericStepper id="weightInput" width="100%" maximum="150" value="55"/>
<mx:Label width="30" text="kg"/>
</mx:HBox>
<mx:HBox width="200">
<mx:Label text="性别"/>
<mx:HBox>
<mx:RadioButtonGroup id="genderRadioGroup"/>
<mx:RadioButton id="rbFemale" label="女" groupName="genderRadioGroup" selected="true"/>
<mx:RadioButton id="rbMale" label="男" groupName="genderRadioGroup"/>
</mx:HBox>
</mx:HBox>
<mx:Button id="btnTest" width="80" label="测试" click="btnTest_clickHandler(event)"
fontWeight="normal"/>
</mx:Application>