我正在尝试计算 BMI 并为数字设置标签,但它一直返回“NaN”而不是数字。
完整代码:
<?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[
public var weightnum:Number;
public var heightnum:Number;
public var resultvar:Number;
protected function button1_clickHandler():void
{
weightnum = Number(weightvar);
heightnum = Number(heightvar);
resultvar = weightnum * 4.4 / (heightnum * heightnum);
resultstr.text = resultvar.toString();
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Label left="30" top="30" text="Your Weight (lbs)"/>
<s:TextInput id="weightvar" restrict="0-9" x="30" y="53" width="80%"/>
<s:Label x="30" y="104" text="Your Height (feet)"/>
<s:TextInput id="heightvar" restrict="0-9" x="30" y="127" width="80%"/>
<s:Button x="30" y="202" label="Calculate" click="button1_clickHandler()"/>
<s:Label id="resultstr" x="30" y="253" text="" />