# Music Quiz-Action Script 2.0-Help Needed

**URL:** https://forum.kirupa.com/t/music-quiz-action-script-2-0-help-needed/269138
**Category:** flash
**Created:** [August 23, 2008, 7:33am UTC](https://forum.kirupa.com/t/music-quiz-action-script-2-0-help-needed/269138 "2008-08-23T07:33:20Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![rachko\_2000](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@rachko\_2000](https://forum.kirupa.com/u/rachko_2000)
#### Post date: [August 23, 2008, 7:33am UTC](https://forum.kirupa.com/t/music-quiz-action-script-2-0-help-needed/269138/1 "2008-08-23T07:33:20Z")

</div>

Hello! I am developing a web based music quiz where the player has to guess the song title from a short clip of music that will be played. I have made the interface, buttons etc and the only problem I now have is:

How do I connect different music clips to the different questions? I am using XML to bring in the questions and answers and am trying to do the same with the music, but it doesnt work! For now I hae made an mp3 player that plays the songs in one long order, but I want Flash to change the songs with the click ot the right button. Because the game always reshuffles the answers I cannot set the ‘change song’ action to a single button…

Please help!!

Here is the actionscript I have used so far!  
LOADER -----------------------  
stop();  
// get the questions  
loadQuestions = new LoadVars();  
loadQuestions.load(“flashtrivia.xml”);  
loadQuestions.onLoad = initQuestions;  
function initQuestions() {  
// break into questions using returns  
// NOTE: character 13 may work better in some cases than character 10  
qArray = loadQuestions.questions.split(String.fro mCharCode(10));  
// break each question into question and answers  
for(i=0;i\<qArray.length;i++) {  
qArray\* = qArray\*.split(":");  
// break the answers apart  
qArray\*[1] = qArray\*[1].split(";");  
}  
// start the game  
\_root.gotoAndPlay(“start game”);  
}  
Main Interactive Section --------------------------------------  
initGame();  
stop();  
function initGame() {  
// set variables  
questionNum = 0;  
score = 0;  
// ask the first question  
displayQuestion();  
}  
function displayQuestion() {  
// see whether all the questions have been asked  
if (questionNum \>= qArray.length) {  
// show final score and end the game  
gotoAndPlay(“game over”);  
} else {  
// rearrange  
answers = shuffleArray(qArray[questionNum][1].slic e(0));  
// place the question and answers on the screen  
question.text = qArray[questionNum][0];  
answer0.text = answers[0];  
answer1.text = answers[1];  
answer2.text = answers[2];  
answer3.text = answers[3];  
// show the question number  
questionNumDisplay = questionNum+1;  
// remember which one is correct  
correctAnswer = qArray[questionNum][1][0];  
// make the text slide in  
animateIn();  
// start potential points at 1000  
potentialPoints = 1000;  
}  
}  
// every frame that goes by subtracts one point  
function scoreCount() {  
// make sure that last answer has arrived  
if (answer3.\_x == 400) {  
// subtract point  
potentialPoints -= 1;  
if (potentialPoints \< 0) potentialPoints = 0;  
}  
}  
// take array1 and shuffle into array 2  
function shuffleArray(array1) {  
// create new, empty array  
array2 = new Array();  
// loop through array  
do {  
// select a random item  
r = int(Math.random()\*array1.length);  
// add item to new array  
array2.push(array1[r]);  
// remove item from old array  
array1.splice(r,1);  
} while (array1.length \> 0);  
// send back the new array  
return(array2);  
}  
function animateIn() {  
// set the location of each answer  
// and set where each should stop  
answer0.xstop = 400;  
answer0.\_x = 800;  
answer1.xstop = 400;  
answer1.\_x = 1000;  
answer2.xstop = 400;  
answer2.\_x = 1200;  
answer3.xstop = 400;  
answer3.\_x = 1400;  
}  
function selectAnswer(n) {  
// correct  
if (answers[n] == correctAnswer) {  
triggerSound(“right”);  
// add score  
score += potentialPoints;  
// ask next question  
questionNum++;  
displayQuestion();  
} else {  
// wrong  
triggerSound(“wrong”);  
// subtract from potential points  
potentialPoints -= 200;  
if (potentialPoints \< 0) potentialPoints = 0;  
// remove the answer  
\_root[“answer”+n].text = “”;  
}  
}  
#include “mp3player.as”
