Re: [Flashcoders] Line break in dynamic text imported from xml

2010-05-20 Thread Paul Jinks
Thanks Ktu

I managed to get this to work by using !CDATA[...]] just as you
suggested. I hadn't understood that it needed to go inside each of my
xml tags.

It's something of a chore, but the quiz is looking a lot better now.

Cheers

Paul



On 19 May 2010 16:38, Ktu ktu_fl...@cataclysmicrewind.com wrote:
 From what I remember when using xml with html, you need to wrap your html
 inside of a* ![CDATA[**]]* to get it to render properly. You can put a \r
 or \n in it as well.


 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 answers (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
        titleMy quiz/title
        items
        item
          questionWhat colour are greenfly/question
          answerRed/answer
          feedbackYou chose answer [a]. This is incorrect. The correct
 answer 

Re: [Flashcoders] Line break in dynamic text imported from xml

2010-05-20 Thread Kerry Thompson
Paul Jinks wrote:

 I managed to get this to work by using !CDATA[...]] just as you
 suggested. I hadn't understood that it needed to go inside each of my
 xml tags.

Just a clarification--it doesn't need to be inside each of your XML
tags. Only the ones that contain text you're going to display,
especially if they have HTML tags like b or \n.

You don't need to make your nodes CDATA (which, by the way, stands for
Character Data--i.e., text).

Cordially,

Kerry Thompson
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Line break in dynamic text imported from xml

2010-05-20 Thread Ktu
and what goes in the CDATA is not parsed by the xml reader.

On Thu, May 20, 2010 at 12:20 PM, Kerry Thompson al...@cyberiantiger.bizwrote:

 Paul Jinks wrote:

  I managed to get this to work by using !CDATA[...]] just as you
  suggested. I hadn't understood that it needed to go inside each of my
  xml tags.

 Just a clarification--it doesn't need to be inside each of your XML
 tags. Only the ones that contain text you're going to display,
 especially if they have HTML tags like b or \n.

 You don't need to make your nodes CDATA (which, by the way, stands for
 Character Data--i.e., text).

 Cordially,

 Kerry Thompson
 ___
 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


Re: [Flashcoders] Line break in dynamic text imported from xml

2010-05-20 Thread Dave Watts
 I managed to get this to work by using !CDATA[...]] just as you
 suggested. I hadn't understood that it needed to go inside each of my
 xml tags.

 Just a clarification--it doesn't need to be inside each of your XML
 tags. Only the ones that contain text you're going to display,
 especially if they have HTML tags like b or \n.

Well, to clarify the clarification - you need to use CDATA whenever
you have contents of an element that may contain unescaped XML
metacharacters: , , ', , . If you don't do this - whether you plan
to display the contents or not - and your element contains a
metacharacter, the XML parser will be unable to parse the file.
Basically, a CDATA block tells the parser to ignore the contents.

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
http://training.figleaf.com/

Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on
GSA Schedule, and provides the highest caliber vendor-authorized
instruction at our training centers, online, or onsite.
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


[Flashcoders] Line break in dynamic text imported from xml

2010-05-19 Thread Paul Jinks
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 answers (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
titleMy quiz/title
items
item
  questionWhat colour are greenfly/question
  answerRed/answer
  feedbackYou chose answer [a]. This is incorrect. The correct
answer is [d]./feedback
  answerBlue/answer
  feedbackYou chose answer [b]. This is incorrect. The correct
answer is [d]./feedback
  answerCheese/answer
  feedbackSorry, cheese is not a colour./feedback
  answer correct=yGreen/answer
  feedbackCorrect!/feedback 
/item
/quiz

Thanks for reading, any help would be very gratefully received.

Paul
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com

Re: [Flashcoders] Line break in dynamic text imported from xml

2010-05-19 Thread Nathan Mynarcik
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 answers (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
        titleMy quiz/title
        items
        item
          questionWhat colour are greenfly/question
          answerRed/answer
          feedbackYou chose answer [a]. This is incorrect. The correct
 answer is [d]./feedback
          answerBlue/answer
          feedbackYou chose answer [b]. This is incorrect. The correct
 answer is [d]./feedback
          answerCheese/answer
          feedbackSorry, cheese is not a colour./feedback
          answer correct=yGreen/answer
          feedbackCorrect!/feedback
        /item
 /quiz

 Thanks for reading, any help would be very gratefully received.

 Paul
 

Re: [Flashcoders] Line break in dynamic text imported from xml

2010-05-19 Thread Ktu
From what I remember when using xml with html, you need to wrap your html
inside of a* ![CDATA[**]]* to get it to render properly. You can put a \r
or \n in it as well.


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 answers (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
titleMy quiz/title
items
item
  questionWhat colour are greenfly/question
  answerRed/answer
  feedbackYou chose answer [a]. This is incorrect. The correct
 answer is [d]./feedback
  answerBlue/answer
  feedbackYou chose answer [b]. This is incorrect. The correct
 answer is [d]./feedback
  answerCheese/answer
  feedbackSorry, cheese is not a colour./feedback
  answer correct=yGreen/answer
  feedbackCorrect!/feedback

Re: [Flashcoders] Line break in dynamic text imported from xml

2010-05-19 Thread Paul Jinks
Thanks for your reply Nathan

I've tried \n and it shows up as plain text the same as \r. I'm not
sure why this should be, but I'll keep digging.

Paul

On 19 May 2010 16:35, Nathan Mynarcik nat...@mynarcik.com wrote:
 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 answers (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
        titleMy quiz/title
        items
        item
          questionWhat colour are greenfly/question
          answerRed/answer
          feedbackYou chose answer [a]. This is incorrect. The correct
 answer is [d]./feedback
          answerBlue/answer
          feedbackYou chose answer [b]. This is incorrect. The correct
 answer is [d]./feedback
          answerCheese/answer
          

Re: [Flashcoders] Line break in dynamic text imported from xml

2010-05-19 Thread Paul Jinks
Thanks Ktu

Yes, that sounds right. However, I'm not trying to enter the text as
html. When I've tried to alter the script to allow this, it's crashed.

I probably ought to go back and fix this properly, but I'm looking for
a way to put line breaks in non-html dynamic text. I'll keep digging
and let you know how I get on.

Paul

On 19 May 2010 16:38, Ktu ktu_fl...@cataclysmicrewind.com wrote:
 From what I remember when using xml with html, you need to wrap your html
 inside of a* ![CDATA[**]]* to get it to render properly. You can put a \r
 or \n in it as well.


 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 answers (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
        titleMy quiz/title
        items
        item
          questionWhat colour are greenfly/question