为什么闪存计算会导致NaN?

时间:2011-03-04 17:45:05

标签: flash

客户要求我在此处重新设置Flash模块:http://www.bendelcorp.com/toolscalculators.html

除压力/真空计算外,一切正常。如果单击该选项卡并在psi字段中输入一个数字,然后单击“计算”,则会使用NaN(不是数字)填充所有字段。

以下是旧版ActionScript:

on (release, keyPress "<Enter>") {
gotoAndStop("pressure/vacuum", 5);
if (inchofwater != "") {
    inchofwaterResult = Number(inchofwater);
    psiResult = Number(inchofwater)*0.03609119066;
    inchofmercuryResult = Number(inchofwater)*0.07348242091;
    barResult = Number(inchofwater)*0.0024884;
    milimeterofmercuryResult = Number(inchofwater)*1.866453491;
    torrResult = Number(inchofwater)*1.866453491;
    meterofwaterResult = Number(inchofwater)*.02537461824;
}
if (bar != "") {
    barResult = Number(bar);
    psiResult = Number(bar)*14.50377377;
    inchofmercuryResult = Number(bar)*29.52998751;
    inchofwaterResult = Number(bar)*401.864652;
    milimeterofmercuryResult = Number(bar)*750.0616827;
    torrResult = Number(bar)*750.0616827;
    meterofwaterResult = Number(bar)*10.19716213;
}
if (inchofmercury != "") {
    inchofmercuryResult = Number(inchofmercury);
    psiResult = Number(inchofmercury)*0.4911540775;
    inchofwaterResult = Number(inchofmercury)*13.60869699;
    barResult = Number(inchofmercury)*0.03386388158;
    milimeterofmercuryResult = Number(inchofmercury)*25.4;
    torrResult = Number(inchofmercury)*25.4;
    meterofwaterResult = Number(inchofmercury)*.3453154908;
}
if (psi != "") {
    psiResult = Number(psi);
    inchofmercuryResult = Number(psi)*2.036020967;
    inchofwaterResult = Number(psi)*27.7075924;
    barResult = Number(psi)*0.06894757293;
    milimeterofmercuryResult = Number(psi)*51.71493257;
    torrResult = Number(psi)*51.71493257;
    meterofwaterResult = Number(psi)*.7030695796;
}
if (milimeterofmercury != "") {
    milimeterofmercuryResult = Number(milimeterofmercury);
    psiResult = Number(milimeterofmercury)*0.0193367747;
    inchofmercuryResult = Number(milimeterofmercury)*0.03937007874;
    inchofwaterResult = Number(milimeterofmercury)*0.5357754719;
    barResult = Number(milimeterofmercury)*0.001333223684;
    torrResult = Number(milimeterofmercury);
    meterofwaterResult = Number(milimeterofmercury)*.01359509806;
}
if (torr !="") {
    torrResult = Number(torr);
    psiResult = Number(torr)*0.0193367747;
    inchofmercuryResult = Number(torr)*0.03937007874;
    inchofwaterResult = Number(torr)*0.5357754719;
    barResult = Number(torr)*0.001333223684;
    milimeterofmercuryResult = Number(torr);
    meterofwaterResult = Number(torr)*.01359509806;
}
if (meterofwater !="") {
    meterofwaterResult = Number(meterofwater);
    psiResult = Number(meterofwater)*1.422334331;
    inchofmercuryResult = Number(meterofwater)*2.89590252;
    inchofwaterResult = Number(meterofwater)*39.40945989;
    barResult = Number(meterofwater)*9806.65E-5;
    milimeterofmercuryResult = Number(meterofwater)*73.55592401;
    torrResult = Number(meterofwater)*73.55592401;
    meterofwaterResult = Number(meterofwater);
}
} 

我会在这里感谢一些帮助。

感谢。

2 个答案:

答案 0 :(得分:0)

if (inchofwater != "")

所有这一切都是测试,如果inchofwater是一个空字符串,而不是它是否计算为数字。数字(“a”)不是空字符串,但毕竟它 NaN。在尝试将其作为字符串转换之前,inchofwater的值是多少?

同样,您在投入的其他原始值是什么,因为您认为用户输入符合您的期望?

答案 1 :(得分:0)

问题在于计算。列出了一些没有相应字段的元素,并且在运行计算之前未将值设置为0,因此我在页面加载时添加了重置,然后正确计算了内容。