A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Textbox, Strings and Pushing Arrays. Any Ideas?

  1. #1
    Member
    Join Date
    Aug 2008
    Posts
    78

    Textbox, Strings and Pushing Arrays. Any Ideas?

    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.
    Attached Files Attached Files

  2. #2
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    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();

  3. #3
    Member
    Join Date
    Aug 2008
    Posts
    78

    textbox, strings and arrays

    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

  4. #4
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    Quote Originally Posted by jarnold View Post
    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();
    __________________

  5. #5
    Member
    Join Date
    Aug 2008
    Posts
    78

    Thanks Chris

    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

  6. #6
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center