私はこれをすべて行うのにかなりの時間を費やしてきました。誰もが助けてくれることを願っています.だから...これは、9つのテキストボックス番号を取得し、それらを動的テキストボックスに追加しています. ここに私の問題があります。
空のテキスト ボックスを 0 に置き換えるにはどうすればよいですか。ユーザーが既にそこにある 0 を取り除くと、NaN になります。以下のifステートメントはそれを修正するはずでしたが、誰かがそれを改善できるかもしれません.
stage.addEventListener(Event.CHANGE, checkTotal); nextQuestion_btn.addEventListener(MouseEvent.MOUSE_DOWN, nextQuestion);
function checkTotal(e:Event){ 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 chores:Number = parseInt(chores_txt.text); var social:Number = parseInt(social_txt.text); var food:Number = parseInt(food_txt.text); var twt:Number = parseInt(twt_txt.text); var partying:Number = parseInt(partying_txt.text); var other:Number = parseInt(other_txt.text); if(work_txt.text==""){ work=0; } if(rnr_txt.text==""){ rnr=0; } if(exerciseB_txt.text==""){ exerciseB=0; } if(exerciseM_txt.text==""){ exerciseM=0; } if(chores_txt.text==""){ chores=0; } if(social_txt.text==""){ social=0; } if(food_txt.text==""){ food=0; } if(twt_txt.text==""){ twt=0; } if(partying_txt.text==""){ partying=0; } if(other_txt.text==""){ other=0; } var total400:Number = work + rnr + exerciseB + exerciseM + chores + social + food + twt + partying + other;
- I can't let my text boxes add up over 400 so as the user types in 399 into one box, if the user types 2 into the next that current text box will revert to 0 because it would be over 400.
I was told using e.currentTarget could solve that problem but I'm not sure how to use it.
All my code...This is my first time on this site so please forgive me for my noobness.
work_txt.maxChars = 3;
rnr_txt.maxChars = 3;
exerciseB_txt.maxChars = 3;
exerciseM_txt.maxChars = 3;
chores_txt.maxChars = 3;
social_txt.maxChars = 3;
food_txt.maxChars = 3;
twt_txt.maxChars = 3;
partying_txt.maxChars = 3;
other_txt.maxChars = 3;
work_txt.restrict = "0-9"
rnr_txt.restrict = "0-9"
exerciseB_txt.restrict = "0-9"
exerciseM_txt.restrict = "0-9"
chores_txt.restrict = "0-9"
social_txt.restrict = "0-9"
food_txt.restrict = "0-9"
twt_txt.restrict = "0-9"
partying_txt.restrict = "0-9"
other_txt.restrict = "0-9";
/*work_txt.text = "0";
rnr_txt.text = "0";
exerciseB_txt.text = "0";
exerciseM_txt.text = "0";
chores_txt.text = "0";
social_txt.text = "0";
food_txt.text = "0";
twt_txt.text = "0";
partying_txt.text = "0";
other_txt.text = "0";*/
var survival:Number = 0;
nextQuestion_btn.visible=false;
stage.addEventListener(Event.CHANGE, checkTotal);
nextQuestion_btn.addEventListener(MouseEvent.MOUSE_DOWN, nextQuestion);
function checkTotal(e:Event){
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 chores:Number = parseInt(chores_txt.text);
var social:Number = parseInt(social_txt.text);
var food:Number = parseInt(food_txt.text);
var twt:Number = parseInt(twt_txt.text);
var partying:Number = parseInt(partying_txt.text);
var other:Number = parseInt(other_txt.text);
if(work_txt.text==""){
work=0;
}
if(rnr_txt.text==""){
rnr=0;
}
if(exerciseB_txt.text==""){
exerciseB=0;
}
if(exerciseM_txt.text==""){
exerciseM=0;
}
if(chores_txt.text==""){
chores=0;
}
if(social_txt.text==""){
social=0;
}
if(food_txt.text==""){
food=0;
}
if(twt_txt.text==""){
twt=0;
}
if(partying_txt.text==""){
partying=0;
}
if(other_txt.text==""){
other=0;
}
var total400:Number = work + rnr + exerciseB + exerciseM +
chores + social + food + twt + partying + other;
trace(work);
trace(rnr);
trace(exerciseB);
trace(exerciseM);
trace(chores);
trace(social);
trace(food);
trace(twt);
trace(partying);
trace(other);
trace(total400);
total400_txt.text = String(total400);
if(total400 >= 400){
nextQuestion_btn.visible=true;
}else{
nextQuestion_btn.visible=false;
}
}