Adding up text boxes
I'm a student leanring action script and my assignment is to make a an application that calculates something. So...
I have 9 input text boxes that should all add up into a dynamic text box. Code below...
var work:Number = parseInt(work_txt.text);
var rnr:Number = parseInt(rnr_txt.text);
var exerciseB:Number = parseInt(exerciseB_txt.text);
var exerciseM:Number = parseInt(exerciseM_txt.text);
var campTent:Number = parseInt(campTent_txt.text);
var campRv:Number = parseInt(campRv_txt.text);
var food:Number = parseInt(food_txt.text);
var twt:Number = parseInt(twt_txt.text);
var partying:Number = parseInt(partying_txt.text);
var total400:Number = work + rnr + exerciseB + exerciseM +
campTent + campRv + food + twt + partying;
stage.addEventListener(Event.ENTER_FRAME, checkTotal) <------- I used an enter frame so the dynamic text box wil update as the user types numbers in.
function checkTotal(e:Event){
if(work_txt.text==""){ <----- All of these are to put a 0 in the text boxes so the app calulates a 0 instead of nothing, having it come out as NaN.
work=0;
}
if(rnr_txt.text==""){
rnr=0;
}
if(exerciseB_txt.text==""){
exerciseB=0;
}
if(exerciseM_txt.text==""){
exerciseM=0;
}
if(campTent_txt.text==""){
campTent=0;
}
if(campRv_txt.text==""){
campRv=0;
}
if(food_txt.text==""){
food=0;
}
if(twt_txt.text==""){
twt=0;
}
if(partying_txt.text==""){
partying=0;
}
total400_txt.text = String(total400); <-------- total400_txt is my dynamic text box that is the total, the other boxes are all of the values the user types in.
}
Thank you in advance for you help! Cheers!
