我的代码中的错误在哪里? AS3

时间:2015-03-25 12:17:21

标签: actionscript-3 actionscript

我试图制作一个简单的问答游戏,但我的代码开始将奇怪的东西传递给问题框文本框。我第一次尝试时代码运行正常。过了一会儿,当我尝试运行测试时,问题框开始显示像a,i,o,r和e这样的随机字符。此外,输入框似乎现在也只接受这些字符。

import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.events.Event;


stop();

start_btn.addEventListener(MouseEvent.CLICK, startQuiz)
function startQuiz(event:MouseEvent):void {
nextFrame();

var questions:Array = new Array;
var answers:Array = new Array;
var userAnswers:Array = new Array;
var grade:String
var score:int = 0;
var quizProgress:int = 0;

var myTextField = new TextField();

// Edit questions here
        questions[0] = "What is x if x - 5 = 3?";
        questions[1] = "What is the square root of 49?";
        questions[2] = "What is the area of a circle whose diameter is 4?";
        questions[3] = "What is 5 + 10?";
        questions[4] = "What is -15 * 2?";
// Edit answers here
        answers[0] = "8";
        answers[1] = "7";
        answers[2] = "12.57";
        answers[3] = "15";
        answers[4] = "-30";


    generateQuestion();



function generateQuestion()
{
    questionbox.text = questions[quizProgress];
}

function updateScore()
{
    for(var i:int = 0; i < questions.length; i++) 
        {
            if(userAnswers[i] == answers[i])
                {
                    score++;
                }
        }
}

function generateGrade()
{
    switch (score)
    {
        case 0:
        grade = "F";
        break;

        case 1:
        grade = "D";
        break;

        case 2:
        grade = "C";
        break;

        case 4:
        grade = "B";
        break;

        case 5:
        grade = "A";
        break;

    }
}


submit_btn.addEventListener(MouseEvent.CLICK, submitAnswer)

function submitAnswer(event:Event):void 
{
    if (quizProgress < 4)
    {
        userAnswers[quizProgress] = inputbox.text;
        quizProgress++;
        generateQuestion();
        inputbox.text = "";
    }
    else
    {
        userAnswers[quizProgress] = inputbox.text;
        quizProgress++
        inputbox.text = "";
        questionbox.text = "";
        updateScore();
        generateGrade();
        submit_btn.removeEventListener(MouseEvent.CLICK, submitAnswer)
        nextFrame();
        grade_text.text = grade;
    }
}

}

0 个答案:

没有答案