Search code examples
actionscript-3flash

AS3 - Making a True/False Quiz with ComboBoxes


So I've been working on a larger project for a while and am having a little confusion with a quiz I am intergrating into it.

I would like to use ComboBoxes to create a true/false quiz. I will be using a switch structure to track the answer of the end-user. I already now how to use a switch structure for ComboBoxes, however, I am unsure as to how I can:

1.) determine if all labels in the ComboBoxes are correct, and; 2.) how I can make my structure evn work. I am having troubles right now.

Please see code below. You will see that it is a logical error. I am unsure of what the issue is, so your help is appreciated again!

Thanks!

-Zero;

import fl.controls.ComboBox;
import flash.events.MouseEvent;

F21next_btn.visible=false; 

firstTF_cb.addItem({label: "True"}); 
firstTF_cb.addItem({label: "False"}); 
secondTF_cb.addItem({label: "True"}); 
secondTF_cb.addItem({label: "False"}); 
thirdTF_cb.addItem({label: "True"}); 
thirdTF_cb.addItem({label: "False"}); 
fourthTF_cb.addItem({label: "True"}); 
fourthTF_cb.addItem({label: "False"}); 
fifthTF_cb.addItem({label: "True"}); 
fifthTF_cb.addItem({label: "False"}); 

F21check_btn.addEventListener(MouseEvent.CLICK, F21checkAnswers); 
F21next_btn.addEventListener(MouseEvent.CLICK, F21goToFrameTwentytwo); 

var firstCB:ComboBox; 
var secondCB:ComboBox; 
var thirdCB:ComboBox; 
var fourthCB:ComboBox; 
var fifthCB:ComboBox; 

firstCB=firstTF_cb; 
secondCB=secondTF_cb; 
thirdCB=thirdTF_cb; 
fourthCB=fourthTF_cb; 
fifthCB=fifthTF_cb; 

function F21goToFrameTwentytwo(event:MouseEvent):void{
    gotoAndStop(22); 
}

//HOW DO U CHECK IF A COMBO BOX ITEM IS TRUE/FALSE AND SELECTED 
function F21checkAnswers(event:MouseEvent):void
{
    switch(firstCB)
    {
        case "True":
        {
            firstQ_txt.textColor=0x00FF00; 
            break;
        }
        case "False":
        {
            firstQ_txt.textColor=0xFF0000; 
            break; 
        }
    }

    switch(secondCB)
    {
        case "True":
        {
            secondQ_txt.textColor=0x00FF00; 
            break; 
        }
        case "False":
        {
            secondQ_txt.textColor=0xFF0000; 
            break; 
        }
    }

    switch(thirdCB)
    {
        case "True":
        {
            thirdQ_txt.textColor=0x00FF00; 
            break; 
        }
        case "False":
        {
            thirdQ_txt.textColor=0x00FF00; 
            break; 
        }
    }

    switch(fourthCB)
    {
        case "True":
        {
            fourthQ_txt.textColor=0x00FF00; 
            break; 
        }
        case "False":
        {
            fourthQ_txt.textColor=0xFF0000; 
            break; 
        }
    }

    switch(fifthCB)
    {
        case "True":
        {
            fifthQ_txt.textColor=0x00FF00; 
            break; 
        }
        case "False":
        {
            fifthQ_txt.textColor=0xFF0000; 
            break; 
        }
    }

}

Solution

  • The selectedLabel property of ComboBox gives the currently selected string of the combo box.

    switch(firstCB.selectedLabel)
    {
        case "True":
        {
            firstQ_txt.textColor = 0x00FF00; 
            break;
        }
        case "False":
        {
            firstQ_txt.textColor = 0xFF0000; 
            break;
        }
    }