A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: If Else statement problem

  1. #1
    Junior Member
    Join Date
    May 2009
    Posts
    4

    If Else statement problem

    Hello everyone. Having a few problems with what I thought was a simple if statement.

    Here is the code:

    on(release){
    if(input=="Expulsion" || input=="expulsion" || input=="Expulsion Method" || input=="expulsion method" ||input=="Expulsion Method")
    {
    sq1++
    shutter01.gotoAndPlay("right");
    }
    else {
    shutter01.gotoAndPlay("wrong");
    }
    }


    I can't quite figure out the small problem with the code. It seems to just bypass the first requirement of the if statement when I do type in the proper input and go straight to the else statement. Any ideas?

  2. #2
    Senior Member vinayak.kadam's Avatar
    Join Date
    Oct 2006
    Location
    gotoAndPlay("Pune");
    Posts
    831
    It is quite obvious that variable input does not holds any of the comparitive values. Can you trace the variable input before the if statement is executed and let us know the results ?
    Last edited by vinayak.kadam; 05-15-2009 at 02:13 AM. Reason: sspelling mistake!
    As ever,
    Vinayak Kadam

  3. #3
    Junior Member
    Join Date
    May 2009
    Posts
    4
    Thanks for the help,

    The input variable is an input text field that the user types the word into.

    Before the question pops up the input variable is set to "blank".

    When the user types the correct answer "Expulsion" it does not go to the right answer movieclip but simply goes straight to the else command, which is the wrong answer movie clip.

    I am not sure why from my script.

  4. #4
    Junior Member
    Join Date
    May 2009
    Posts
    4
    I traced the input variable. It initially says it is "blank" which it should before the user enters the input text field.

    However there was no trace after the answer was entered and clicked submit.

  5. #5
    Senior Member vinayak.kadam's Avatar
    Join Date
    Oct 2006
    Location
    gotoAndPlay("Pune");
    Posts
    831
    Can you upload your FLA plz.......so that I can check in it directly and solve teh issue!
    As ever,
    Vinayak Kadam

  6. #6
    Junior Member
    Join Date
    May 2009
    Posts
    4
    fla attached.


    updated:

    Figured it out Vinayak.

    Since it was an input text field I needed to put - .text after the name of the field. So

    on(release){
    if(input.text=="Expulsion" || input.text=="expulsion" || input.text=="Expulsion Method" || input.text=="expulsion method" ||input.text=="Expulsion Method")
    {
    sq1++
    shutter01.gotoAndPlay("right");
    }
    else {
    shutter01.gotoAndPlay("wrong");
    }
    }

    works perfectly now.
    Attached Files Attached Files
    Last edited by glorybe23; 05-19-2009 at 11:30 AM.

  7. #7
    Senior Member
    Join Date
    Nov 2005
    Location
    dante's inferno
    Posts
    904
    try:

    button code
    PHP Code:
    on (release) {
        
    _root.myText _root.myInput_txt.text;
        
    trace('myText:'+_root.myText);
        if (
    _root.myText == "Expulsion" || _root.myText == "expulsion" || _root.myText == "Expulsion Method" || _root.myText == "expulsion method" || _root.myText == "Expulsion Method") {
            
    trace('correct');
            
    sq1++;
            
    shutter01.gotoAndPlay("right");
        } else {
            
    trace('incorrect');
            
    shutter01.gotoAndPlay("wrong");
        }

    main timeline:
    PHP Code:
    var myText ''
    text box instance name:
    PHP Code:
    myInput_txt 
    textbox variable field in property inspector empty


    IMS

  8. #8
    Senior Member vinayak.kadam's Avatar
    Join Date
    Oct 2006
    Location
    gotoAndPlay("Pune");
    Posts
    831
    Well done........It feels great when we solve the problem on our own and most of the times these are silly problems....
    As ever,
    Vinayak Kadam

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