0

工学部の学生が使用する健康と安全に関するクイズを作成しています。

16 カテゴリの質問を含む .txt ファイルが提供されました。

これを自分で行う方法についてのチュートリアルを検索しましたが、ガイドの形式を理解できません。

誰かがこの主題について私を啓発することができますか? Actionscript 3.0 を使用しています

参照用にファイルの最初の数行を次に示します。

Ref || Question || AnswerA || AnswerB || AnswerC || AnswerD || AnswerE || Correct || Answer || Type || File
1.1 || Who has responsibility for health and safety on site ? || The client and main contractor only || Self - employed contractors only and employees || Employers, employees and sub - contractors || Everyone on site no matter who employs them || || D || Everyone at work has a legal duty to look after their own health and safety. || o_4 || _
1.2 || Which of the following is correct for risk assessment ? || It is a good idea to do, but not essential || Only do it if it is a big job || It is a legal requirement and must always be done || Only needs to be done for hazardous work || || C || Risk assessments are always necessary because they show how people are likely to be harmed. || o_4 || _
1.3 || Why should regular inspections of the workplace take place ? || To check whether the working environment is safe || To check that everyone is doing their job || To prepare for a visit from an HSE Inspector || To check that all staff are present || || A || If regular inspections are not carried out, the workplace could become an unsafe place. || o_4 || _
1.4 || The letters CDM stand for : || Control of Demolition(and Management) Regulations || Construction(Demolition Management) Regulations || Construction(Design and Management) Regulations || Control of Dangerous Materials Regulations || || C || The CDM Regulations aim to ensure that health and safety is addressed in a structured and organised manner during the design, construction, maintenance and demolition phases of all projects to which the regulations apply. || o_4 || _

これが混乱を招く場合は申し訳ありませんが、誰かが返信して理解するのが難しい場合は、さらに理解する必要があるかもしれないことを喜んで示します.

ありがとうございました。

::EDIT:: 私が抱えている問題は、Actionscript 3.0 を介してこのファイルを自分のシーンに呼び出す方法さえ理解していないことです。

4

1 に答える 1

1

まず、ローダーを使用してデータを読み込むことができます。

質問を格納する配列を作成します。

var questions:Array = [ ];

ローダーをインスタンス化し、ロードが完了したときのイベント リスナーを追加します。

var request:URLRequest = new URLRequest("questions.txt");
var loader:URLLoader = new URLLoader(request);

loader.addEventListener(Event.COMPLETE, completeHandler);

完了したら、区切り文字のデータ ファイルを解析し、||質問を配列に保存します。

function completeHandler(event:Event):void
{
    // loader data - the questions.txt file
    var data:String = event.target.data;

    // split data by newline for each question
    var lines:Array = data.split("\n");

    // for every line
    for each (var line:String in lines)
    {
        // split line by "||" delimiter
        var question:Array = line.split("||");

        // add the question to the questions array:
        questions.push({ref: question[0],
                        question: question[1],
                        answerA: question[2],
                        answerB: question[3],
                        answerC: question[4],
                        answerD: question[5],
                        answerE: question[6],
                        correct: question[7],
                        answer: question[8],
                        type: question[9],
                        file: question[10]});
    }
}

これで、各質問は質問配列の要素になります。

たとえば、質問を繰り返すには:

for each (var question:Object in questions)
{
    trace("question: " + question.question);
    trace("answer:   " + question.answer);
    trace("type:     " + question.type);
    trace("file:     " + question.file);
}

または、質問をランダムに選択するには:

var question:Object = questions[Math.floor(Math.random() * questions.length)];

trace("question: " + question.question);
trace("answer:   " + question.answer);
trace("type:     " + question.type);
trace("file:     " + question.file);
于 2013-03-29T01:32:12.973 に答える