2009-09-28 5 views
0

다양한 자습서를 사용하여 AS3에서 다음 퀴즈를 만들었습니다. 역동적이고 중요한 기능을 사용하여 전체를 설정하고 퀴즈 및 배열을 관리하는 카운터를 사용합니다. 답변을 선택하면 체크 버튼을 클릭 한 다음 "다음"버튼을 클릭하십시오. 어떤 이유로 든 setup() 함수를 호출하면 퀴즈가 이동하지 않고 오류가 표시됩니다. 쓸데없는 것들을 편집 한 짧은 코드가 붙어있어서, 몇 가지 제안을 듣고 싶습니다. (그렇지 않으면AS3 퀴즈 - 다음 질문으로 어떻게 이동합니까?

var i:Number=0; 

function setup():void { 

, 당신은 '내가 ++'와 함께 증가 및 호출 설정을 '있어 :

function setup():void { 

var i:Number=0; 

에 : 은 BTW, 외국어는

var arrQuestion:Array = [ "?מיהו סטיב ג'ובס", "מהי משמעות הקיצור WWW?"]; 
var arrAnswers:Array = [["AOL מנכל","יור אורקל","מנכל אפל","מנכל סאן"], ["World Wide Web", "With Web Wins", "Wired Web Window", "Wap Windows War"]]; 
var arrCorrect:Array = [3, 1]; 
var btnNext:myNext = new myNext(); 


setup(); 

function setup():void { 

var i:Number=0; 


var thequestion_txt:TextField= new TextField; 
addChild(thequestion_txt); 

var feedback_txt:TextField= new TextField; 
addChild(feedback_txt); 

var radio1:RadioButton = new RadioButton(); 
var radio2:RadioButton = new RadioButton(); 
var radio3:RadioButton = new RadioButton(); 
var radio4:RadioButton = new RadioButton(); 

var radioGrp:RadioButtonGroup = new RadioButtonGroup("radioGrp"); 

addChild(radio1); 
addChild(radio2); 
addChild(radio3); 
addChild(radio4); 


radio1.label = arrAnswers[i][0]; 
radio1.value = 1; 
//etc.. 

var checkButton:Button = new Button(); 
addChild(checkButton); 
checkButton.x =230; 
checkButton.y = 300; 
checkButton.label = "בדוק"; 


checkButton.addEventListener(MouseEvent.CLICK, clickHandler); 
function clickHandler(event:MouseEvent):void { 

    addChild(btnNext); 
    btnNext.x =230; 
    btnNext.y = 300; 
    if (radioGrp.selection.value == (arrCorrect[i])) { 
    feedback_txt.text = "!נכון מאוד"; 
    btnNext.addEventListener(MouseEvent.CLICK, myRemove); 


    } else { 
    feedback_txt.text = "תשובה שגויה"; 
    btnNext.addEventListener(MouseEvent.CLICK, myRemove); 


    } 


} 
function myRemove(e:MouseEvent):void { 
    removeChild(thequestion_txt); 
    removeChild(feedback_txt); 
    removeChild(radio1); 
    removeChild(radio2); 
    removeChild(radio3); 
    removeChild(radio4); 
    removeChild(checkButton); 
    removeChild(btnNext); 
    //chaning the counter to change the question and answers 
    i++; 
    //shouldn't the call to setting up the entire stage again be here? 
    //it is't working, I dont get the next question. 
    setup(); 

} 
} 

답변

4

변화 : 히브리어) ', 그러면 다시'i '가 0으로 재설정되고 증분이 발생하지 않습니다.

P. '코드 샘플'형식을 사용하면 예제의 가독성이 크게 향상됩니다.

+0

+1은 코드 포맷을 설명하는 데 유용합니다. 실제로는 가독성이 대폭 향상 될 것입니다. – Cameron

+0

카메론, 답변 해 주셔서 감사합니다. 코드 샘플 형식을 사용했지만 나중에 편집 할 때 결함이 발생하여 작동하지 않는다고 생각합니다. 감사합니다. – Sarit

관련 문제