;

PDA

Click to See Complete Forum and Search --> : Textbox, Strings and Pushing Arrays. Any Ideas?


jarnold
05-21-2009, 09:07 AM
Hi Bret,
Still trying to get past this text box problem. I've got to this point with help

var correctString="The sad man";
var correctArray=correctString.split(' ');

txt2.onChanged=function(){
var inArray=this.text.split(' ');
var resultArray=new Array();
for(i=0;i<correctArray.length;i++){
if(inArray[i]==correctArray[i]){
resultArray[i]='correct';
gotoandStop(3);
}else{

resultArray[i]=' not correct "' + correctArray[i] +'"-------';
}


}
txt3.text=(resultArray)
}
Selection.setFocus("txt2var");
stop();


But
1. it goes to frame 3 even if only first word is correct should only do it if all correct.
2. how can I not show the incorrect words ie have *** instead of sad?

PS can no one solve the koolmoves exchange menu1 problem - 189 views but only you responding.

Chris_Seahorn
05-22-2009, 03:37 AM
1. it goes to frame 3 even if only first word is correct should only do it if all correct.
2. how can I not show the incorrect words ie have *** instead of sad?




var correctString = "The sad man";
var correctArray = correctString.split(' ');

txt2.onChanged = function(){
var inArray = this.text.split(' ');
var resultArray = new Array();
for(i=0;i<correctArray.length;i++){
if(inArray[i] == correctArray[i]){
resultArray[i] = 'correct';
// gotoandStop(3);
}else{
var foo1 = "";
for(j = 0; j < correctArray[i].length; j++){
foo1 += "*";
}
resultArray[i]=' not correct "' + foo1 +'"-------';
}
txt3.text=(resultArray)

}
var foo2 = 0;
for(k = 0;k<resultArray.length;k++){
if(resultArray[k] == 'correct'){
foo2++;
}
}
if(foo2 == resultArray.length){
gotoandStop(3);
}
}
Selection.setFocus("txt2var");
stop();

jarnold
05-22-2009, 04:32 AM
Thank for this Chris - works great.
If you have the time can you tell me what I did wrong?
Why is the word now ***
thanks to you and Bret for answering this forum
ja

Chris_Seahorn
05-22-2009, 04:10 PM
Why is the word now ***


You wanted it to display as "***" correct? I went by your wording here:

2. how can I not show the incorrect words ie have *** instead of sad?

You didn't do anything wrong per se. I'll explain what this is doing with comments.....

var correctString = "The sad man";
var correctArray = correctString.split(' ');

txt2.onChanged = function(){
var inArray = this.text.split(' ');
var resultArray = new Array();
for(i=0;i<correctArray.length;i++){
if(inArray[i] == correctArray[i]){
//word typed was correct, push value of 'correct' to resultArray
resultArray[i] = 'correct';
//I removed the line below for use later on
// gotoandStop(3);
}else{
//if we are inside this else clause, the user typed wrong word so we...
//create a foo1 var and initialize it as an empty string always
var foo1 = "";
//we are going to find out the length of the correct word so we can display asterisks that are correct to length
for(j = 0; j < correctArray[i].length; j++){
//create the asterisk replacement which will be the same length as the correct word
foo1 += "*";
}
//build display string as you did in earlier examples but showing the asterisk version NOT the correct word
resultArray[i]=' not correct "' + foo1 +'"-------';
}
//display the string which shows asterisks
txt3.text=(resultArray)

}
//create a foo2 var and initialize it with an integer of zero always
var foo2 = 0;
//check our resultArray to see number of correct words (value of "correct" in array) that have been typed
for(k = 0;k<resultArray.length;k++){
if(resultArray[k] == 'correct'){
//correct word found, increment foo2
foo2++;
}
}
//to finish up the loop we check the foo2 count against the resultArray length. If it matches all words were correct. Step forward in movie.
if(foo2 == resultArray.length){
gotoandStop(3);
}
}
Selection.setFocus("txt2var");
stop();
__________________

jarnold
05-23-2009, 01:52 AM
Hi Chris,
I meant how does "sad" become "***" (which you've answered). That's a great set of comments for me to learn how to do this. Feel bad having to keep asking you guys.
Thanks again,
John

blanius
05-23-2009, 09:42 AM
John we never mind answering well asked questions. I think Chris would agree with me that we enjoy helping that's why we're here. I learn as much as I teach as I usually don't know the answer when people ask but I try to solve it as if it were my own problem and figure it out then share my research, thus learning something new for myself.