Files:
============
Quiz.fla
– Create this file with flash 8.
– Create a movie clip and export it
for as 2.0 name(mcImage)
– Drag that movie clip onto the stage,
in the top left corner…
– Create a Layer called “a” (actions) open the actions
panel, and type the following.

#include “main.as”
#include “xmlHandler.as”

stop();


– Create another Layer called “Questions”
– This Layer will hold all of the form fields.
– dynamic Text Fields
===================
– tQstnNum
– tQuestion
– lblCorrect
– tAnswerText
– tChcNumber0
– tChcAnswer0
– tChcNumber1
– tChcAnswer1
– tChcNumber2
– tChcAnswer2
– … all the way till what ever you want… each
field holds a quetion, and a number of the the question.

– Buttons
===================
– from the components panel, expand the user
interface, and drag 4 buttons on the stage – name the buttons
– btnPrevious
– btnNext
– btnPause
– btnPlay
View the example
Download Files
Quiz.xml
===============

<Quiz>
<question correct=“” number=“”>
<questionText></questionText>
<choice>
<ChoiceText ChoiceID=“”></ChoiceText>
</choice>
<sound></sound>
<answerText></answerText>
<jpg>assets/Images/Session1Intro.jpg</jpg>
</question>

<question correct=“A,B,E,F,H,I” number=“1”>
<questionText>Which of the following are rate schedule designations for transportation services offered by Northern?</questionText>
<choice>
<ChoiceText ChoiceID=“A”>TF</ChoiceText>
<ChoiceText ChoiceID=“B”>TFX</ChoiceText>
<ChoiceText ChoiceID=“C”>FDD</ChoiceText>
<ChoiceText ChoiceID=“D”>IDD</ChoiceText>
<ChoiceText ChoiceID=“E”>GS-T</ChoiceText>
<ChoiceText ChoiceID=“F”>LFT</ChoiceText>
<ChoiceText ChoiceID=“G”>PDD</ChoiceText>
<ChoiceText ChoiceID=“H”>SMS</ChoiceText>
<ChoiceText ChoiceID=“I”>TI</ChoiceText>
</choice>
<sound>assets/Sounds/SLIDE_01.MP3</sound>
<answerText></answerText>
<jpg>assets/Images/NorthernNaturalGasHeader.jpg</jpg>
</question>

<question correct=“C,D,G” number=“2”>
<questionText>Which of the following are rate schedule designations for storage services offered by Northern?</questionText>
<choice>
<ChoiceText ChoiceID=“A”>TF</ChoiceText>
<ChoiceText ChoiceID=“B”>TFX</ChoiceText>
<ChoiceText ChoiceID=“C”>FDD</ChoiceText>
<ChoiceText ChoiceID=“D”>IDD</ChoiceText>
<ChoiceText ChoiceID=“E”>GS-T</ChoiceText>
<ChoiceText ChoiceID=“F”>LFT</ChoiceText>
<ChoiceText ChoiceID=“G”>PDD</ChoiceText>
<ChoiceText ChoiceID=“H”>SMS</ChoiceText>
<ChoiceText ChoiceID=“I”>TI</ChoiceText>
</choice>
<sound>assets/Sounds/SLIDE_02.MP3</sound>
<answerText></answerText>
<jpg>some.jpg</jpg>
</question>

<question correct=“B” number=“3”>
<questionText>TF Service can be purchased for a term of only five months.</questionText>
<choice>
<ChoiceText ChoiceID=“A”>True</ChoiceText>
<ChoiceText ChoiceID=“B”>False</ChoiceText>
</choice>
<sound>assets/Sounds/SLIDE_03.MP3</sound>
<answerText></answerText>
<jpg>some.jpg</jpg>
</question>

<question correct=“B” number=“4”>
<questionText>TF Service in the Field Area is referred to as:</questionText>
<choice>
<ChoiceText ChoiceID=“A”>TFX</ChoiceText>
<ChoiceText ChoiceID=“B”>TFF</ChoiceText>
<ChoiceText ChoiceID=“C”>TXF</ChoiceText>
<ChoiceText ChoiceID=“D”>TFXF</ChoiceText>
</choice>
<sound>assets/Sounds/SLIDE_04.MP3</sound>
<answerText></answerText>
<jpg>some.jpg</jpg>
</question>

<question correct=“A” number=“5”>
<questionText>Which tier of TF Service has the lowest reservation rate?</questionText>
<choice>
<ChoiceText ChoiceID=“A”>TF12 base</ChoiceText>
<ChoiceText ChoiceID=“B”>TF12 variable</ChoiceText>
<ChoiceText ChoiceID=“C”>TF5</ChoiceText>
<ChoiceText ChoiceID=“D”>TFX base</ChoiceText>
</choice>
<sound>assets/Sounds/SLIDE_05.MP3</sound>
<answerText></answerText>
<jpg>some.jpg</jpg>
</question>
</Quiz>

this xml file holds a series of xml questions…

in the file

main.as
=========

var mcMain:MovieClip = this;

btnNext.onPress = function() {
getNextQuestion();
}

btnPrevious.onPress = function() {
getPreviousQuestion();
}

// declare a new XML instance var xmlQuestions:XML = new XML();

function init() {
// ignore tabs, returns, and other whitespace between nodes xmlQuestions.ignoreWhite = true;

// set the scope of the onLoad function to the main timeline, not xmlQuestions
xmlQuestions.onLoad = Delegate.create(this, onXmlLoaded);

// start loading the file xmlQuestions.load (“Quiz.xml”);

}

// initialize the xml init();

the load of the project is done in the following as file

xmlHandler.xml
==================

function onXmlLoaded(success:Boolean) {
if (success) {
// trace(‘the xml got loaded successfully’); //set the xml file to be global so we dont have to load it anymore //similar to a query of queries in coldfusion. _global.xmlQuestions = xmlQuestions

var xnRoot : XMLNode = _global.xmlQuestions.firstChild; //trace(xnRoot);
_global.currentQuestion = 0;
_global.recordCount = xnRoot.childNodes.length;

getFirstQuestion();

/******************************
* the following are for the sounds
* ****************************/
} else {
// do whatever you want to do if an XML read error occurred trace(‘xml failed’)
}
}

function getFirstQuestion():Void {
getQuestionAt(0);
};

function getPreviousQuestion():Void {
//if it’s greater than the first record (0) then move to previous… else… dont… if (_global.currentQuestion > 0){
//do manipulation tempQuestion = _global.currentQuestion – 1
getQuestionAt(tempQuestion);
} else {
//trace (‘at the beginning’); //have to reset the recordCount to – 1 because of array numbering var tempRecordCount = _global.recordCount – 1
getLastQuestion(tempRecordCount)
};
};

function getNextQuestion():Void {

var tempQuestion = _global.currentQuestion + 1;
//test to see if we are at the end if (tempQuestion < _global.recordCount){
//do manipulation tempQuestion = _global.currentQuestion + 1
getQuestionAt(tempQuestion);
} else {
//trace (‘at the end’); //have to reset the recordCount to + 1 because of array numbering var tempRecordCount = _global.recordCount + 1
getFirstQuestion();
};
};

function getLastQuestion(i:Number):Void {
getQuestionAt(i);
};

function getAllQuestions():Void {

for (var i : Number = 0; i < _global.recordCount; i ++)
{
getQuestionAt(i);
};
};

//getQuestionAt is used by all the other functions! it’s the main function! function getQuestionAt(i:Number):Void {
var xnRoot : XMLNode = _global.xmlQuestions.firstChild; //trace(xnRoot); var xnQuestion : XMLNode = xnRoot.firstChild;//get Text in Node var xnNumber : XMLNode;//attribute var xnCorrect : XMLNode;//attribute var xnChoice : XMLNode;//next node within question var xnChoiceText : XMLNode;//next node within question var xnChoiceTextID : XMLNode;//attribute of ChoiceText var xnSound : XMLNode;//next node within question var xnAnswerText : XMLNode;//next node within question var xnJpg : XMLNode;//next node within question

xnQuiz = xnRoot.childNodes [i]; //trace(xnQuiz); xnQuestion = xnQuiz.firstChild; // gets all first children xnNumber = xnQuiz.attributes.number;
xnCorrect = xnQuiz.attributes.correct;
xnChoice = xnQuestion.nextSibling; //trace(xnChoice.childNodes[0]);
tQstnNum.text = xnQuiz.attributes.number + “.”;
tQuestion.text = xnQuestion.firstChild.nodeValue;
//trace (xnQuiz.attributes.number + “. “ + xnQuestion.firstChild.nodeValue); //Loop through the choice array\\

/************************
* declare form fields for array
************************/
var aChoiceNumber = new Array();

aChoiceNumber[0] = tChcNumber0;
aChoiceNumber[1] = tChcNumber1;
aChoiceNumber[2] = tChcNumber2;
aChoiceNumber[3] = tChcNumber3;
aChoiceNumber[4] = tChcNumber4;
aChoiceNumber[5] = tChcNumber5;
aChoiceNumber[6] = tChcNumber6;
aChoiceNumber[7] = tChcNumber7;
aChoiceNumber[8] = tChcNumber8;

var aChoiceAnswer = new Array();

aChoiceAnswer[0] = tChcAnswer0;
aChoiceAnswer[1] = tChcAnswer1;
aChoiceAnswer[2] = tChcAnswer2;
aChoiceAnswer[3] = tChcAnswer3;
aChoiceAnswer[4] = tChcAnswer4;
aChoiceAnswer[5] = tChcAnswer5;
aChoiceAnswer[6] = tChcAnswer6;
aChoiceAnswer[7] = tChcAnswer7;
aChoiceAnswer[8] = tChcAnswer8;

tQuestion.autoSize = true;

tChcAnswer0.autoSize = true;
tChcAnswer1.autoSize = true;
tChcAnswer2.autoSize = true;
tChcAnswer3.autoSize = true;
tChcAnswer4.autoSize = true;
tChcAnswer5.autoSize = true;
tChcAnswer6.autoSize = true;
tChcAnswer7.autoSize = true;
tChcAnswer8.autoSize = true;

for (var j : Number = 0; j < xnChoice.childNodes.length; j ++)
{
xnChoiceText = xnChoice.childNodes[j];
xnChoiceTextID = xnChoiceText.attributes.ChoiceID; //trace(xnChoiceID);
aChoiceAnswer[j].text = xnChoiceText.firstChild.nodeValue;
aChoiceNumber[j].text = xnChoiceTextID + “.”;

for (var k : Number = xnChoice.childNodes.length;k < aChoiceAnswer.length; k++)
{
aChoiceAnswer[k].text = “”;
aChoiceNumber[k].text = “”;
}

//trace(xnCorrect + ” vs. “ + xnChoiceTextID); //trace (” “ + xnChoiceTextID + “. “ + xnChoiceText.firstChild.nodeValue); };

xnSound = xnChoice.nextSibling; //trace (“Sound: “ + xnSound.firstChild.nodeValue); xnAnswerText = xnSound.nextSibling;
lblCorrect.text = “Answer: “ + xnCorrect;
//tAnswerText.text = xnAnswerText.firstChild.nodeValue; //trace (“AnswerText: “ + xnAnswerText.firstChild.nodeValue);
xnJpg = xnAnswerText.nextSibling; //trace (“Image: “ + xnJpg.firstChild.nodeValue);
mcImage.loadMovie(xnJpg.firstChild.nodeValue, 5);

_global.currentQuestion = i; //set the new current question loadMP3(xnSound.firstChild.nodeValue);
};

function loadMP3(filename:String):Void{
this.createEmptyMovieClip(“mcSoundHolder”, this.getNextHighestDepth());
sndAudio = new Sound(mcSoundHolder);
sndAudio.loadSound(filename, false);

sndAudio.onLoad = function(bSuccess:Boolean):Void {
if(bSuccess){
sndAudio.start();
} else {
trace(‘there was an error opening the file’);
};
};

var nInterval:Number = setInterval(checkProgress,1000);
function checkProgress():Void{
var nPercent:Number = Math.round((sndAudio.getBytesLoaded()/sndAudio.getBytesTotal()) * 100);
//trace(nPercent); };

/*********************************
* the play and pause or any other sound buttons must go within the loadMP3() function
* *******************************/
btnPlay.onPress = function() {
sndAudio.start(sndAudio.position/1000);
};

btnPause.onPress = function() {
sndAudio.stop();
};

};