A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Help with a text field quiz for a learning object.

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    3

    Help with a text field quiz for a learning object.

    So basically the quiz is about identifying textures in images. The first image shows the texture of a shell. I would like the user to be able to type into a input text field what they think the texture is. They then click a "check answer" button, if the answer they typed in was shell then "Correct" will be displayed in a dynamic text field if they typed in anything else, than "Incorrect" will be displayed in the dynamic text field.

    Could someone please help me with actionscript for this button, im using actionscript 2 in flash cs4.

    I found this code on the internet but it doesn't work,


    on (release) {
    if (input_instance_name=="correct answer"){
    display_instance_name.text="Correct!";
    }
    else{
    display_instance_name.text="Wrong!";
    }
    }

  2. #2
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    The code you were provided looks correct it just needs to be modified... try something like this.

    PHP Code:
    on(release) {
        if(
    input_instance_name.text == "shell") {
            
    display_instance_name.text "Correct";
        } else {
            
    display_instance_name.text "Incorrect";
        }

    Wile E. Coyote - "Clear as mud?"

  3. #3
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    What Robb@exo said, but also remember to give your input and dynamic text fields, INSTANCE NAMES, and NOT VARIABLE NAMES, otherwise, the code ^above won't work!

    Another note, what if they type in UPPERCASE or mixed? Then the coding won't work. Either embed only LOWERCASE characters (or UPPERCASE), or use this code on a Frame:

    Actionscript Code:
    input_instance_name.restrict = "a-z";

    that's for LOWERCASE only, but for UPPERCASE:

    Actionscript Code:
    input_instance_name.restrict = "A-Z";

    just make sure to change your answer in Robb@exo's code snippet, to plain LOWERCASE or UPPERCASE, depending on what you chose to restrict
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  4. #4
    Registered User
    Join Date
    Sep 2011
    Posts
    3

    Thankyou

    Thank you for your help robb@exo and Nig13,

    this is what I used and it worked

    on(release) {
    if(shell_input.text == "shell") {
    shell_dynamic.text = "Correct";
    } else {
    shell_dynamic.text = "Incorrect";
    }
    }


    however I am not sure how to add in Nig13's suggestion to restrict text input to lower case letters only.

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