A Flash Developer Resource Site

Results 1 to 19 of 19

Thread: [RESOLVED] timing errors and string mismatch

  1. #1
    Member
    Join Date
    Aug 2014
    Posts
    51

    resolved [RESOLVED] timing errors and string mismatch

    Hi all and Fruitbeard !!

    Kindly have a look at the attached file. The Big window displays a word and if I type the same in the box labelled "Ans", I should get a message saying that the displayed and inputted texts match. Instead I just keep getting "Incorrect". Can't figure why?

    Secondly, the program is supposed to loop through the program twice as can easily be seen. The timings are correct the first time through and the second time through the loop, except that at the start of the second loop, for the very first word, word 1, the time for which it is displayed, is just 1 second whereas it should be about 5 seconds as is for all the words after and for that matter before it.

    Please figure these out for me.

    Thanks all !
    Attached Files Attached Files

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Without really going to town on your code, you need to give boxAns.text its instance name of boxAns, I'm sure there is some other things that could fine tune, but that will get you going.

    I would also recommend not using the vars on the text field variable box, instead use textfield.text = myVar, but it's your choice sir.

  3. #3
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi Ajoo,

    Your file was a tad mixed up, perhaps this will be enlightening

  4. #4
    Member
    Join Date
    Aug 2014
    Posts
    51
    Hi fruitbeard,

    Thanks for the reply. I tried the boxAns but it did not work. I guess it got left unchanged in the file. So I have tried to get the myWord to match the myAns using the variable myAns as well as using a boxAns.text instance. I did give the input textbox the instance name when i tried it. I have used that once again by not using the vars on the text field variable, yet no success in getting them to match.

    Thanks for the post with the file but I beg to say that I have Flash version CS3. Is there any way that you could save that in a lower version. I would be grateful. or maybe you can send me the AS2 code in a text file and I'll go thru the same and try in it my fla. (unless th fla itself is modified).

    Quote " Your file was a tad mixed up, perhaps this will be enlightening ". - fruitbeard.

    That's a scary line. I admit I am a novice but was the program so bad?

    Thanks loads !! You are the Guru !
    Last edited by ajoo; 09-26-2014 at 06:24 AM.

  5. #5
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Take a look at the attached fla.

    It was ok, you had too many unneeded intervals and timeouts conflicting
    Last edited by fruitbeard; 09-26-2014 at 06:30 AM.

  6. #6
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    OK, CS3 , its very awkward for me to do it for CS3, so this is the last time, CS5 and above for me, you will need to update to open my files from now.

  7. #7
    Member
    Join Date
    Aug 2014
    Posts
    51
    Quote Originally Posted by fruitbeard View Post
    Hi,

    OK, CS3 , its very awkward for me to do it for CS3, so this is the last time, CS5 and above for me, you will need to update to open my files from now.
    Yes Sir, Thank you. Will upgrade. Will also be glad to check and see the conflicts that I caused. I tried a whole lot, almost a day, to get the timing error eliminated but failed.

    Will revert once I have checked the file out. Thanks very much for all the trouble.

  8. #8
    Member
    Join Date
    Aug 2014
    Posts
    51
    Hi fruitbeard,

    So i just went through the file and it is works fine except that the functionality is different from what I have tried to achieve in the file I sent. Actually it's my fault and I should have mentioned the functionality that I was trying to achieve. I thought that running my file would demonstrate it but I guess it was subtle.

    What I wanted was that the word be displayed for 4 seconds and then be removed for the next 4 seconds ( dispBlank) but during the entire duration( 8 seconds or so - 4 seconds of word displayed and 4 seconds of blank displayed), the user would have a chance to input the word and the spellings would be matched at the end and the correct / incorrect message displayed accordingly before the next word was displayed. That way I can change the duration of the words for which the word is flashed on the screen and then the user gets a chance to type it back in ( you know like checking if the words is remembered and spelled correctly by the user.)

    But now after looking at your code and comparing with mine I feel that there would be a problem of matching since the bigText would have to be changed to a blank to make it disappear and that would never make bigText.Text == myWord. Some sort of improvisation will have to be made. Maybe like use another variable into whom the bigText.Text value is stored before bigText is set to blank.

    That's the reason I used the wait etc. and an additional Timeout / SetInterval. Kindly look at the code again in light of this functionality and get it timed correct.

    Thanks very much.
    PS. I still do not have the CS5 but I will upgrade very soon. Please send a text file of the code if the CS3 is a hassle. Thanks.

  9. #9
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    I don't have time right now, however, if you look at the code you will notice I use the vars too, i just set the text to dsiplay the vars, the vars remain the same until next word, so kindly get it timed correct.

  10. #10
    Member
    Join Date
    Aug 2014
    Posts
    51
    Hi fruitbeard,

    The reason I was not getting a match between the displayed and the user input was exactly as mentioned in the last message. Assigning the "" ( blank ) value to myWord to clear the word after 4 seconds was foiling the match. The small improvisation I mentioned in the last message got it working. I owe this to you again since your code made me think of this.

    I simply did :

    myWord = v_word[word];
    myCheckWord = myWord;

    and then using this value to check for a match

    if(myCheckWord == myAns)
    instead of if(myWord == myAns)

    and lo I got the match. So there is no need to use the box instance name. Just the variable names work fine.

    Now it's an issue of the timing that I request you to look into.

    Thanks loads.

  11. #11
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    PHP Code:
    stop();

    var 
    word:Number 0;
    var 
    wordNum:Number 0;

    var 
    initialTimer:Number;
    var 
    showWordTime:Number;
    var 
    hideWordTime:Number;
    var 
    wordMessager:String;

    var 
    myResult:Number 0;

    var 
    v_word:Array = ["bat""sat""mat"];
    var 
    f_word:Array = ["hay""day""bay"];

    var 
    myWord:String "";
    var 
    myAns:String "";

    var 
    whichArray:Array;

    if (
    loop == 1)
    {
        
    maxWords v_word.length;
    }
    else
    {
        
    maxWords f_word.length;
    }
    //trace("maxWords = " + maxWords);

    if (langType == "ENG")
    {
        
    whichArray v_word;
    }
    if (
    langType == "FRN")
    {
        
    whichArray f_word;
    }
    trace("Using array: " whichArray);

    initialTimer setTimeout(displayWord1000);

    function 
    displayWord()
    {
        
    clearTimeout(initialTimer);

        
    myWord whichArray[word];

        
    boxAns.text "";
        
    bigText.text myWord;

        if (
    word == maxWords)
        {
            if (
    loop == 1)
            {
                
    loop 2;
                
    gotoAndPlay("Loop");
            }
            else
            {
                
    bigText.text "";
                
    wordNumText.text "";
                
    OutMsg.resultText.text "End of list.";
                
    OutMsg._alpha 100;
                
    trace("Complete");
                return;
            }
        }
        else
        {
            
    wordNum++;
            
    wordNumText.text wordNum;
            
    showWordTime setTimeout(hideWord4000);
        }
    }

    function 
    displayWordCheck()
    {
        
    clearTimeout(hideWordTime);

        
    trace("MyAns = " boxAns.text "  MyWord = " myWord);

        if (
    boxAns.text == myWord)
        {
            
    wordMessager " The Answer is correct !! ";
        }
        else
        {
            
    wordMessager " Incorrect.  ";
        }

        
    myWord "";
        
    myAns "";
        
    word++;
        
    fadeout(wordMessager);
        
    //myResult = 0;
    }

    function 
    fadeout(fadeMsg:String)
    {
        
    OutMsg._alpha 100;
        
    OutMsg.resultText.text fadeMsg;
        
    onEnterFrame = function ()
        {
            if (
    OutMsg._alpha 0)
            {
                
    OutMsg._alpha -= 5;
            }
            else
            {
                
    delete onEnterFrame;
                
    displayWord();
            }
        };
    }

    function 
    hideWord()
    {
        
    clearTimeout(showWordTime);
        
    bigText.text "";
        
    hideWordTime setTimeout(displayWordCheck4000);


  12. #12
    Member
    Join Date
    Aug 2014
    Posts
    51
    Hi fruitbeard,

    Thanks for the reply. I have found one more error in my code which has improved the situation somewhat but not fully rectified it. I had made a mistake in the if then conditional loops in dispWord(). I was using :

    if( word == MaxWords ) {... }
    which is ok and then using

    if(word <= Maxwords) {... }
    which was wrong and I changed it to

    if(word < Maxwords) {... }

    With this the first word in the array, going second time through the loop is displayed for the right time. Earlier it was displaying for a very short time almost just 1 second.

    However now the blank is displayed for a lesser time ( only for the first word looping second time) as compared to the blank displayed for the rest of the words. The blank for the first word is almost between 2-3 seconds as compared to 5 seconds for the rest of the words.

    I am attaching the new file too for you to check out.
    I'll be glad if you would figure this out.

    Thanks loads for all your help, time n effort.
    Attached Files Attached Files

  13. #13
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    look above

  14. #14
    Member
    Join Date
    Aug 2014
    Posts
    51
    Hi fruitbeard,

    I think we are running out of sync !! lol ! just posted a message and then saw another one from you. Will check this out now and revert.

    Thanks !

  15. #15
    Member
    Join Date
    Aug 2014
    Posts
    51
    Hi !! checked your code and it ran perfect !! Thanks loads. I'll compare yours with mine and try and locate where the fault lies in mine.

    Thanks loads and extremely grateful.

  16. #16
    Member
    Join Date
    Aug 2014
    Posts
    51
    Hi fruitbeard,

    Yea perfect. The code was sweet, succinct and clear. Wish I could think straight like you. I know this is solved but it still baffles me as to what is causing that small glitch in my code. If you have time then I would request you to look at it again and see where it's going wrong. I am sure you would be able to spot it in no time. It would be a great lesson in debugging for me.

    Thanks loads for all your help !!

  17. #17
    Member
    Join Date
    Aug 2014
    Posts
    51
    Hi fruitbeard,
    Please do not bother to find that glitch. I just managed to find the flaw. Did prove to be a great debugging lesson. Thanks very much again for all your help.

  18. #18
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Actually I didn't try, somebody else downloaded it!!
    Glad you found the error Ajoo, saved me debugging it and wasting a whole lot of time.

  19. #19
    Member
    Join Date
    Aug 2014
    Posts
    51
    Thanks fruitbeard,

    learning a lot from the way you code. Eternally grateful.

Tags for this Thread

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