【问题标题】:Parameter passing for multiple text fields that are gathered in an array?为数组中收集的多个文本字段传递参数?
【发布时间】:2018-06-23 12:11:41
【问题描述】:

所以,我有一个问题。我目前正在开展一个教育项目,教授细胞器的基础知识。我有指向每个细胞器的线条,我希望用户能够在其中输入每个细胞器的名称(如图表)。当用户正确完成工作后,我将显示下一步按钮。

但是,为了让用户能够继续,我需要一种方法来跟踪学生的答案是否正确。我为此使用参数传递。

我希望能够返回真/假。如果所有答案都返回真,则用户可以前进。如果有一个答案是错误的,则会显示一条消息。

如何使用参数传递来确定用户的回答是对还是错?文本字段也在一个数组中......

这里是代码。

谢谢!

-零;

    import flash.events.MouseEvent;

var organelleInput:Array=[F18nucleolusInput_txt, F18nucleusInput_txt, F18erInput_txt, F18golgiInput_txt, F18vacuoleInput_txt, F18chloroplastInput_txt, F18lysosomeInput_txt, F18mitochondriaInput_txt]; 

F18next_btn.visible=false; 

F18next_btn.addEventListener(MouseEvent.CLICK, F18goToFrameNineteen); 
F18back_btn.addEventListener(MouseEvent.CLICK, F18goToFrameSix); 
checkMyWork_btn.addEventListener(MouseEvent.CLICK, checkAnswers); 


function checkAnswers(event:MouseEvent):void
{
    var answer:String; 
    var correctAnswers:Boolean; 
    var incorrectAnswers:Boolean; 

    answer = organelleInput[i]; 
    correctAnswers=checkCorrectAnswers(answer); 

    for(var j:int=0; j<organelleInput.length; j++)
    {
        organelleInput[j].restrict="a-z";

        if(correctAnswers==true)
        {
            F18output_txt.text="Well done!"; 
            F18next_btn.visible=true; 
            checkMyWork_btn.visible==false; 
        }

        if(correctAnswers==false)
        {
            F18output_txt.text="One of them seems to be wrong. Try again."; 
        }
    }
}



function F18goToFrameNineteen(event:MouseEvent):void{
    gotoAndStop(19); 
}

function F18goToFrameSix(event:MouseEvent):void{
    gotoAndStop(6); 
}

function checkCorrectAnswers(s:String):Boolean 
{
    if(F18nucleolusInput_txt.text=="nucleolus"){
        return true; 
    }
    return false; 

    if(F18nucleusInput_txt.text=="nucleus"){
        return true; 
    }
    return false; 

    if((F18erInput_txt.text=="endoplasmic reticulum")||(F18erInput_txt.text=="er")){
        return true; 
    }
    return false; 

    if((F18golgiInput_txt.text=="golgi body")||(F18golgiInput_txt.text=="golgi apparatus")){
        return true; 
    }
    return false; 

    if((F18mitochondriaInput_txt.text=="mitochondria")||(F18mitochondriaInput_txt.text=="mitochondrion")){
        return true; 
    }
    return false; 

    if((F18lysosomeInput_txt.text=="lysosome")||(F18lysosomeInput_txt.text=="lysosomes")){
        return true; 
    }
    return false; 

    if(F18vacuoleInput_txt.text=="vacuole"){
        return true; 
    }
    return false; 

    if((F18chloroplastInput_txt.text=="chloroplast")||(F18chloroplastInput_txt.text=="chloroplasts")){
        return true; 
    }
    return false; 
}

【问题讨论】:

    标签: actionscript-3


    【解决方案1】:

    您可以检查 TextFieldArrayArrayArray

    var Correct:Array = [
        ["nucleolus"],
        ["nucleus"],
        ["golgi body", "golgi apparatus"],
        ["mitochondria", "mitochondrion"]
    ];
    var Answers:Array = [T1, T2, T3, T4];
    
    // Returns true if all answers are correct.
    function allCorrect():Boolean
    {
        for (var i:int = 0; i < Answers.length; i++)
            if (!oneCorrect(Answers[i], Correct[i]))
                return false;
    
        return true;
    }
    
    // Returns true if answer is on the Array of correct answers.
    function oneCorrect(source:TextField, target:Array):Boolean
    {
        return target.indexOf(source.text.toLowerCase()) > -1;
    }
    

    【讨论】:

      猜你喜欢
      • 2017-10-26
      • 1970-01-01
      • 2021-11-04
      • 2017-09-26
      • 2019-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多