2013-01-28 2 views
1
answer = new Array(); 
answer[0] = "1997"; 
answer[1] = "1941"; 
question = new Array(); 
question[0] = "What ...?"; 
question[1] = "Why ...?"; 

question_txt.text = question; 
enter1.onRelease = function() 
{ 
    if (answer_input.text == answer) 
    { 
     answer++; 
     question++; 
     question_txt.text = question; 
    } 
    else 
    { 
     answer_input.text = "Incorrect"; 
    } 
}; 

Там в 2 текстовых поля и кнопка TextBox1 = question_txt - что для отображения вопроса и типа [Dynamic] TextBox2 = answer_input - которая позволяет пользователям, чтобы попытаться ответить на этот вопросAS2 Ответ Input Quiz

Ценности ответов и вопросов просто составлены, имейте это в виду.

Так почему же это не работает?

ответ

1

Ну, я не эксперт as2, но похоже, что question - это массив, и вы пытаетесь установить question_txt.text на question, что на самом деле является целым массивом. И потом, вы пытаетесь добавить 1 в массивы answer и question, которые не будут работать.

Что вы действительно хотите сделать, это получить элементы этих массивов, и для этого вам нужно передать индекс в свой массив. (question [0] = «Первый элемент в массиве вопросов») Итак, вам нужна переменная, которая отслеживает индекс этих массивов, которые вы используете в настоящее время. Что-то вроде этого ...

answer = new Array(); 
answer[0] = "1997"; 
answer[1] = "1941"; 
question = new Array(); 
question[0] = "What ...?"; 
question[1] = "Why ...?"; 

qanda_number = 0; 


question_txt.text = question[qanda_number]; 
enter1.onRelease = function() 
{ 
    if (answer_input.text == answer[qanda_number) 
    { 
     qanda_number++; 
     question_txt.text = question[qanda_number]; 
     // You probably want to empty out your answer textfield, too. 
    } 
    else 
    { 
     answer_input.text = "Incorrect"; 
    } 
}; 
+0

имеет смысл, но даже этот код не работает, я попытался изменить тексты переменных тоже, но это не работает. – lorcanO33

+0

Теперь он благодарит много – lorcanO33

0
answer = new Array(); //Create a list of answers. 
answer[0] = "Insert Answer"; //Answer is ... 
answer[1] = "Insert Answer"; //Answer1 is ... 
question = new Array(); //Create a list of questions. 
question[0] = "Insert Question"; //Question is ... 
question[1] = "Insert Question"; //Question1 is .. 
index = 0; //Create an index number to keep answers and questions in order 

onEnterFrame = function() //Constantly... 
{ 
    question_txt.text = question[index] //Make the question in tune with the index num 
}; 



button.onRelease = function() //On the release of a button... 
{ 
    if (answer_input.text == answer[index]) //if the User's guess is correct - proceed 
    { 
     index++; //Move up in the Index 
     answer_input.text = ""; //Reset the User's guess 
    } 
    else 
    { 
     answer_input.text = "Incorrect"; //Display Incorrect over the User's guess 
    } 
}; 
+0

Готово! Здесь для всех нужно следовать – lorcanO33