I was asked by a client to reskin a Flash module here: http://www.bendelcorp.com/toolscalculators.html
Everything works correctly except the Pressure/Vacuum calcul开发者_开发问答ation. If you click on that tab and enter a number in the psi field and then click calculate it populates all fields with NaN (not a number).
Here is the legacy 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);
}
}
I would appreciate some help here.
Thanks.
if (inchofwater != "")
All this does is test if inchofwater is an empty string, not whether it evaluates to a number. Number("a") is not an empty string, but it is NaN, after all. What is the value of inchofwater before attempting to cast it as a String?
Likewise, what are your other raw values that you're casting as Number on faith that the user input is what you expect?
The problem was in the calculations. There were a couple of elements that were listed that there were no corresponding fields for and the values were not being set to 0 before the calculations were being run, so I added a reset to the page when it loaded and then things were calculated correctly.
精彩评论