A Flash Developer Resource Site

Results 1 to 20 of 35

Thread: external questions file

Hybrid View

  1. #1
    Junior Member
    Join Date
    Apr 2006
    Posts
    5

    My Quiz

    Hi could anyone tell me what is going wrong with my quiz? I want to randomise the order by telling Flash to assign the variable shufflearray to the question nodes but it doesnt seem to work when I try this.

    The code is below:

    function QuizItem(question)
    {
    this.question=question;
    this.answers=new Array();
    this.numOfAnswers=0;
    this.correctAnswer=0;
    this.getQuestion=function()
    {
    return this.question;
    }
    this.addAnswer=function(answer, isCorrectAnswer)
    {
    this.answers[this.numOfAnswers]=answer;
    if (isCorrectAnswer)
    this.correctAnswer=this.numOfAnswers;
    this.numOfAnswers++;
    }

    this.getAnswer=function(answerNumberToGet)
    {
    return this.answers[answerNumberToGet];
    }

    this.getCorrectAnswerNumber=function()
    {
    return this.correctAnswer;
    }

    this.checkAnswerNumber=function(userAnswerNumber)
    {
    if (userAnswerNumber==this.getCorrectAnswerNumber())
    gotoAndPlay(22);
    else
    gotoAndPlay(32);
    }
    }

    function onQuizData(success)
    {
    var quizNode=this.childNodes[0];
    var quizTitleNode=quizNode.firstChild;
    title=quizTitleNode.firstChild.nodeValue;

    var i=0;
    // <items> follows <title>
    var itemsNode=quizNode;
    while (itemsNode.childNodes[i])
    {
    var itemNode=itemsNode.childNodes[i];
    // <item> consists of <question> and one or more <answer>
    // <question> always comes before <answer>s (node 0 of <item>)
    var questionNode=itemNode.childNodes[0];
    quizItems[i]=new QuizItem(questionNode.firstChild.nodeValue);
    var a=1;
    // <answer> follows <question>
    var answerNode=itemNode.childNodes[a++];
    while (answerNode)
    {
    var isCorrectAnswer=false;
    if (answerNode.attributes.correct=="y")
    isCorrectAnswer=true;
    quizItems[i].addAnswer(answerNode.firstChild.nodeValue, isCorrectAnswer);
    // goto the next <answer>
    answerNode=itemNode.childNodes[a++];
    }
    i++;
    }

    //I think you need to make an array 1 to maxNumberOfQuestions i.e

    function sortRand () {
    if (random(2) == 0) {
    return -1;
    }
    if (random(2) == 0) {
    return 1;
    }
    }
    questionarray = [1,2,3,4,5,6,7,8,9,10,11,12];
    shuffledArray = questionarray.sort(sortRand); //trace(shuffledArray);

    //use this shuffled array to access different nodes of your quiz xml i.e.

    nextQuestion = QuizItem[shuffledArray[0]]; <!--This is the line -->

    delete shuffledArray[0];

    //then delete shuffledArray[0]

    ////////////

    gotoAndStop(12);
    }

    var quizItems=new Array();
    var myData=new XML();
    myData.ignoreWhite=true;
    myData.onLoad=onQuizData;
    myData.load("Quiz 1 - How youll develop the skills & reasons -1144.xml");

    Thanks

    Chris Girgg

  2. #2
    Junior Member
    Join Date
    Aug 2006
    Posts
    18
    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

  3. #3
    Junior Member
    Join Date
    Oct 2005
    Posts
    9

    Next button for Quiz

    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

  4. #4
    DesignMercenary
    Join Date
    Aug 2006
    Posts
    10

    HTML in question text?

    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center