Hi I am developing some kind of a quiz for my personal tutorial in flash and am in need of some help here. Could you email me the .fla. Thanx in advance.
[email protected]
thanx again
Printable View
Hi I am developing some kind of a quiz for my personal tutorial in flash and am in need of some help here. Could you email me the .fla. Thanx in advance.
[email protected]
thanx again
Hopefully someone is still reading this...
I stumbled across this thread a few weeks back and it has proven invaluable in creating a reusable quiz framework for a client who is setting up interactive kiosks inside a large facility. My sincere thanks to everyone who contributed. However...
I have added an "explanation" attribute to the XML question tags, so that after an answer is chosen, they are shown "right" or "wrong" and then an explanation comes up which shows the correct answer and some extra information. Like so:
<question q="Which planet is closest to the Sun?"
ans_a="Pluto"
ans_b="Mercury"
ans_c="Uranus"
ans_d="Saturn"
ans_exp="Mercury is the innermost planet in our solar system, orbiting the Sun once every 88 days."
right="b">
This works beautifully, but the problem now is that the client wishes to add some HTML/CSS support to the explanation, to highlight the correct answer within the text (ans_exp="<b>Mercury</b> is the innermost planet ..." with the <b> being styled with inline or an external CSS doc).
But of course adding HTML tags to the <question> tag attributes breaks the XML load.
I'm relatively new to using XML in Flash, but I'm thinking that the most likely change that needs to be made is to set up the XML using nested elements instead of attributes, like so:
<question>
<q>Which planet is closest to the Sun?</q>
<ans_a>Pluto</ans_a>
<ans_b>Mercury</ans_b>
<ans_c>Uranus</ans_c>
<ans_d>Saturn</ans_d>
<ans_exp><b>Mercury</b> is the innermost planet in our solar system, orbiting the Sun once every 88 days.</and_exp>
<right>b</right>
</question>
However, I have no idea how to accomplish this transition.
Is this the correct approach? Is there an easier way?
You'd need to wrap your HTML text inside a CDATA tag in order to avoid breaking the XML...ie:
code:
<ans_exp><![CDATA[<b>Mercury</b> is the innermost planet in our solar system, orbiting the Sun once every 88 days.]]></and_exp>
Consequently you'll need to adjust your XML parsing to drill down another node into the CDATA...
HTH,
K.
deadbeat - Thanks for the response. However, I'm still working from an XML file that uses single <question> tags w/attributes, like so:
<question q="Which planet is closest to the Sun?"
ans_a="Pluto"
ans_b="Mercury"
ans_c="Uranus"
ans_d="Saturn"
ans_exp="Mercury is the innermost planet in our solar system, orbiting the Sun once every 88 days."
right="b">
And I can't put the CDATA tag within the attribute...
Well, then you'll either need to restructure the XML, or abandon the idea of adding HTML tags to it...
K.
Right. And what I'm asking is, if I restructure the XML, how do I get the AS to parse it?
Maybe this phrases the question better:
The following AS:
[frame 1]
[frame 2]Code:qList = new Array();
nbrUsed = 0;
loadNode = function(it) {
if (it.nodeName == 'question') {
var qSet = new Array();
qSet.q = it.attributes['q'];
qSet.used = false;
qSet.ans_a = it.attributes['ans_a'];
qSet.ans_b = it.attributes['ans_b'];
qSet.ans_c = it.attributes['ans_c'];
qSet.ans_d = it.attributes['ans_d'];
qSet.ans_exp = it.attributes['ans_exp'];
qSet.right = it.attributes['right'];
qList.push(qSet);
}
if (it.hasChildNodes()) {
for (var i = 0; i < it.childNodes.length; ++i)
loadNode(it.childNodes[i]);
}
}
function finishInit() {
trace(qList.length + " questions loaded");
qList.sort(function() {return random(3) - 1;});
questionNbr = qList.length-5;
maxscore = (qList.length-questionNbr);
gotoAndPlay(2);
}
var quizXML = new XML();
quizXML.onLoad = function() {
qList = new Array();
loadNode(this);
finishInit();
}
quizXML.load("quiz.xml");
Parses an XML document with multiple tags like this:Code:if (questionNbr >= qList.length)
gotoAndPlay("end");
question = qList[questionNbr].q;
answerA = qList[questionNbr].ans_a;
answerB = qList[questionNbr].ans_b;
answerC = qList[questionNbr].ans_c;
answerD = qList[questionNbr].ans_d;
explain = qList[questionNbr].ans_exp;
right = qList[questionNbr].right;
This works perfectly. What I WANT to be able to do is include HTML tags inside the text. So, assuming I restructure the XML like so (with CDATA tag as per deadbeat's response):Code:<question q="Which planet is closest to the Sun?"
ans_a="Pluto"
ans_b="Mercury"
ans_c="Uranus"
ans_d="Saturn"
ans_exp="Mercury is the innermost planet in our solar system, orbiting the Sun once every 88 days."
right="b">
What has to happen to the AS to properly create the question array from this new XML?Code:<question>
<q>Which planet is closest to the Sun?</q>
<ans_a>Pluto</ans_a>
<ans_b>Mercury</ans_b>
<ans_c>Uranus</ans_c>
<ans_d>Saturn</ans_d>
<ans_exp><![CDATA[<b>Mercury</b> is the innermost planet in our solar system, orbiting the Sun once every 88 days.]]></ans_exp>
<right>b</right>
</question>
Something like this should work:
code:
if (it.nodeName == 'question') {
var nodes=it.childNodes;
qSet.q = nodes[0].firstChild.nodeValue;
qSet.used = false;
qSet.ans_a = nodes[1].firstChild.nodeValue;
qSet.ans_b = nodes[2].firstChild.nodeValue;
qSet.ans_c = nodes[3].firstChild.nodeValue;
qSet.ans_d = nodes[4].firstChild.nodeValue;
qSet.ans_exp = nodes[5].firstChild.nodeValue;
qSet.right = nodes[6].firstChild.nodeValue;
qList.push(qSet);
}
K.
Okay, this code appears to be loading the restructured XML file (the trace(qList.length) is showing the correct # of questions loaded), but none of the question or answer text fields are displaying text.
Does the frame 2 code (below) need to change at all?
Code:// Select next question in array (which is already randomly shuffled)
if (questionNbr >= qList.length)
gotoAndPlay("end");
question = qList[questionNbr].q;
answerA = qList[questionNbr].ans_a;
answerB = qList[questionNbr].ans_b;
answerC = qList[questionNbr].ans_c;
answerD = qList[questionNbr].ans_d;
explain = qList[questionNbr].ans_exp;
right = qList[questionNbr].right;
Try adding a couple of traces for debugging purposes:
code:
if (questionNbr >= qList.length)
gotoAndPlay("end");
}
trace("length= "+qList.length);
trace("questionNbr= "+questionNbr);
var item=qList[questionNbr];
trace("item= "+item);
for(var i in item){
trace(i+" = "+item[i]);
}
K.
Getting back to the original post about creating a Quiz....
Everything is working perfectly for me as is, but I would like to add in one more function. My quiz has 3 difficultly levels. I've modified the quiz that Jim originally posted to jump to a frame called 'round2' when all the questions have been answered correctly. This part works fine.
Once in 'round2' I duplicated the movieclip that ran the initial set of questions and just modified the code to look for 'questions2.xml' (as opposed to 'questions.xml' in the 'round1' movieclip. The problem I get is that the movie automatically jumps to the end (as the code tells it to do in frame 2 if all the questions have been answered). I tried removing this line of code to see where the problem started and now whereever the questions/answers should be displayed it says 'undefined / undefined / undefined /undefined / undefined'.
Is this happening because it's using the same code as before to look in an Array for what's been used and what hasn't? I tried adding a 2 to all the functions and variables (i.e. q is now q2 / question is now question2) and still nothing.
Little help...
- Chris
Nevermind. There was a problem with my 'questions2.xml' file. I had an apostrophe in one of the questions and that was screwing everything up. It works fine now.
Hey All,
how would I change the code above to pause before going to the next question?
I know I would need to make the button invisible until the user clicked the answer but I am a newbie at actionsript and am not quite sure how to proceed
I PM'ed you char74 hope that doesn't bother you...I wanted to know if I could get a opy of what you did on the Texas site...I was able to get jBums script to work, however I need the ability to provide feedback..I have a clcunky way of doing it...but it doesn't keep score correctly after I hit the next button...I would love to see your end result .FLA hopefully now my haor will start growing back.
Thanks I will PM you my email address
How do you put a pause button to allow the user to see the feedback....I tried your code and it shows the feeback at lightning speedQuote:
Originally Posted by jweeks123
Hi,
Now I would like to random the answers. How can I do that? Thanks for your help.