I believe you can use "\n" in your feedback string and it makes a new line.




On Wed, May 19, 2010 at 10:56 AM, Paul Jinks <p...@pauljinks.co.uk> wrote:
> It's been a long time since I've done any coding. I think this is
> pretty straightforward but it has me beat. Can you help?
>
> I'm working on a quiz using AS1 (I think) that reads questions and
> answers from an xml file. (see below for the script).
>
> I'd like to introduce line breaks into the feedback, how do I do this?
> I've tried using \r but it just displays this as text.
>
> Ideally I'd like to display the text as html but so far my efforts to
> do this have broken the script - any pointers?
>
> Here's the action script for the quiz. I hope it makes sense:
>
> function QuizItem(question)
> {
>        this.question=question;
>        this.answers=new Array();
>        this.feedbacks=new Array();
>        this.numOfAnswers=0;
>        this.correctAnswer=0;
>        this.getQuestion=function()
>        {
>                return this.question;
>        }
>        this.addAnswer=function(answer, isCorrectAnswer, feedback)
>        {
>                this.answers[this.numOfAnswers]=answer;
>                this.feedbacks[this.numOfAnswers]=feedback;
>                if (isCorrectAnswer)
>                        this.correctAnswer=this.numOfAnswers;
>                this.numOfAnswers++;
>        }
>
>        this.getAnswer=function(answerNumberToGet)
>        {
>                return this.answers[answerNumberToGet];
>        }
>        this.getFeedback=function(answerNumberToGet)
>        {
>                return this.feedbacks[answerNumberToGet];
>        }
>
>        this.getCorrectAnswerNumber=function()
>        {
>                return this.correctAnswer;
>        }
>
>        this.checkAnswerNumber=function(userAnswerNumber)
>        {
>                if (userAnswerNumber==this.getCorrectAnswerNumber()) {
>                        numOfQuestionsAnsweredCorrectly++;
>                } else {
>                        numOfQuestionsAnsweredIncorrectly++;
>                }
>                feedback = _root["feedback"+parseInt((userAnswerNumber+1))]
>                gotoAndPlay("Feedback");
>        }
> }
>
> function onQuizData(success)
> {
>        var quizNode=this.firstChild;
>        var quizTitleNode=quizNode.firstChild;
>        title=quizTitleNode.firstChild.nodeValue;
>
>        var i=0;
>        // <items> follows <title>
>        var itemsNode=quizNode.childNodes[1];
>        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)
>                {
>                        //trace(answerNode);
>                        var isCorrectAnswer=false;
>                        if (answerNode.attributes.correct=="y")
>                                isCorrectAnswer=true;
>                        //get answer
>                        tempAnswer = answerNode.firstChild.nodeValue;
>                        //go to next node
>                        answerNode=itemNode.childNodes[a++];
>                        //get feedback
>                        tempFeedback = answerNode.firstChild.nodeValue;
>                        //add answer and feedback to current answer/feedback 
> 'pair'
>                        quizItems[i].addAnswer(tempAnswer, isCorrectAnswer, 
> tempFeedback);
>                        // goto the next <answer>
>                        answerNode=itemNode.childNodes[a++];
>                }
>                i++;
>        }
>        gotoAndStop("Start");
> }
>
> var quizItems=new Array();
> var myData=new XML();
> myData.ignoreWhite=true;
> myData.onLoad=onQuizData;
> myData.load("google_quiz.xml");
> stop();
>
> And this is what the xml file looks like:
>
> <!DOCTYPE quiz [
>        <!ELEMENT quiz (title, items)>
>        <!ELEMENT title (#PCDATA)>
>        <!ELEMENT items (item)+>
>        <!ELEMENT item (question, answer, answer+)>
>        <!ELEMENT question (#PCDATA)>
>        <!ELEMENT answer (#PCDATA)>
>        <!ELEMENT feedback (#PCDATA)>
>        <!ATTLIST answer correct (y) #IMPLIED>
> ]>
> <quiz>
>        <title>My quiz</title>
>        <items>
>        <item>
>          <question>What colour are greenfly</question>
>          <answer>Red</answer>
>          <feedback>You chose answer [a]. This is incorrect. The correct
> answer is [d].</feedback>
>          <answer>Blue</answer>
>          <feedback>You chose answer [b]. This is incorrect. The correct
> answer is [d].</feedback>
>          <answer>Cheese</answer>
>          <feedback>Sorry, cheese is not a colour.</feedback>
>          <answer correct="y">Green</answer>
>          <feedback>Correct!</feedback>
>        </item>
> </quiz>
>
> Thanks for reading, any help would be very gratefully received.
>
> Paul
> _______________________________________________
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to