2013-01-28 4 views
1
2 개 텍스트 상자와 버튼 TextBox1에 = question_txt있다
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"; 
    } 
}; 

- 질문을 표시하는 것입니다 및 유형이다 [Dynamic] TextBox2를 = answer_input - 사용자가 질문에 대답을 시도 할 수 있도록하는 것입니다있는AS2 대답 입력 퀴즈

답변 및 질문의 가치는 막 만들어졌습니다. 괜찮습니다.

그럼 왜 작동하지 않습니까?

답변

1

글쎄, 나는 전문가는 아니지만 question이 배열 인 것 같습니다. question_txt.textquestion으로 설정하려고합니다. 실제로는 전체 배열입니다. 그리고 나서 나중에 answerquestion 배열에 1을 더하려고 시도하는데 이는 작동하지 않습니다.

당신이 정말로하고자하는 것은 요소의 배열에 액세스하는 것입니다. 그렇게하려면 배열에 인덱스를 전달해야합니다. (question [0] = "question 배열의 첫 번째 요소") 그래서 필요한 것은 현재 사용중인 배열의 색인을 추적하는 변수입니다. 나도 변수에 텍스트를 변경하려고했지만 그 중 하나가 작동하지 않습니다, 이런 식으로 뭔가 ...

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