1

クイズアプリケーションを書いています。すべての質問と回答のオプションは、このアクションコードスクリプトで画面に表示されるxmlansから取得されます

  for (i=0; i < numberOfQuestions; i++) {

                    var questionTextField = new TextField();
                    addChild(questionTextField);
                    questionTextField.text=i + "  " +  myXML.QNODE[i].QUESTION.text();
                    questionTextField.name="q"+i;

                    questionTextField.width=400;
                    questionTextField.x= 0;
                    questionTextField.y=i * 100;

                    generateAnswers(i);

                }

ただし、最初に5つの質問を表示し、次に5つの質問を表示します。どうすればこれを行うことができますか?

4

1 に答える 1

0

You could parse the XML up-front so that you have all the questions in an Array. You could then abstract the loop which creates the questions into a function which takes parameters for the question index (which you would increment as each set of questions is completed) and the pagination limit (the number of questions to display each time). You'll also need a routine to clear up the question fields each time (you might consider storing the fields on an Array for management). Something like the following:

var questions:Array = parseXML();
showQuestions(0, 5);

    function parseXML():Array
    {
        var arr:Array = [];

        for (i=0; i < numberOfQuestions; i++) {
            arr.push(myXML.QNODE[i].QUESTION.text());
        }

        return arr;
    }

    function showQuestions(index:int, limit:int):void
    {
        for (var i:int = index; i <= (index + limit); i ++) 
        {
            var questionTextField = new TextField();
            addChild(questionTextField);
            questionTextField.text=i + "  " +  questions[i];
            questionTextField.name="q"+i;

            questionTextField.width=400;
            questionTextField.x= 0;
            questionTextField.y=i * 100;

            generateAnswers(i);     
        }
    }

    function clearQuestions():void 
    {
        // Routine to clear old questions
    }
于 2013-01-05T01:19:38.613 に答える