Reputation: 3
i have created a formula sheet, with basically 1 input field which will return 4 results, and a calculate button. on a right input, right results, which i have no problem. on a blank input, the results should remain blank with error message at the bottom. but right now the results somehow returned a "a", and the calculate button does not work when the right input is in. my codes' below, appreciate advice.
import flash.events.MouseEvent;
calculate_btn.addEventListener(MouseEvent.CLICK,calculateClick);
var inputNum:String;
var tRes:Number;
var mRes: Number;
var sRes: Number;
function calculateClick(event:MouseEvent):void{
if (inputNum != ""){
inputNum = inputTxt.text;
tRes = Math.round((parseInt(inputNum) * 10000 / 3600)*10)/10;
tRes.toString();
tCal.text = String(tRes);
mRes = tRes * 20;
mCal.text = String(mRes);
sRes = mRes - 556;
sCal.text = String(sRes);
} else if (inputNum == "") {
tCal.text = "";
mCal.text = "";
sCal.text = "";
warningTxt.text = "Error! Please input!";
}
}
Upvotes: 0
Views: 101
Reputation: 1016
Ok I think I have it working. I did change the calc on the line "tRes = Math.round(inputNum * 10000 / 3600)" but you should be able to change it back to what you had without any problems.
calculate_btn.addEventListener(MouseEvent.CLICK,calculateClick);
var inputNum:Number;
var tRes:Number;
var mRes: Number;
var sRes: Number;
function calculateClick(event:MouseEvent):void{
inputNum = Number(inputTxt.text);
if (!isNaN(inputNum)){
tRes = Math.round(inputNum * 10000 / 3600)
tCal.text = String(tRes);
mRes = tRes * 20;
mCal.text = String(mRes);
sRes = mRes - 556;
sCal.text = String(sRes);
warningTxt.text = "";
} else {
tCal.text = "";
mCal.text = "";
sCal.text = "";
warningTxt.text = "Error! Please input!";
}
}
Upvotes: 1