|
-
[RESOLVED] on XML load ... goes to last Item
I have a quiz that loads questions, answers and a wrong answer response from an XML file.
Everything is working fine except when it loads the text for the "wrongresponse" variable it always loads the last item value regardless of the question. It skips right to the last Item element everytime.
Last edited by ADVaughn; 05-18-2012 at 01:26 PM.
-
The AS above is on frame 1 maintimeline, I call the "wrongresponse" variable on frame 23 using;
Actionscript Code:
wrongresponse=wrongresponse;
There is a dynamic text field on that frame that uses that variable
-
Prid - Outing
I am back, guys ... and finally 18 :P
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
-
Hey buddy you have been a big help for me before. Hope you can help again.
I have made some headway since posting this. I can now get it to load the value for the "wrongresponse" element but on the first question it comes up undefined the remaining 9 questions it loads the "wrongresponse" element from the xml but is one behind. ie displays Question 5 wrong response when is hould be displaying the one for Question 6.
Thanks Guy
Last edited by ADVaughn; 05-18-2012 at 01:23 PM.
-
-
Last edited by ADVaughn; 05-18-2012 at 01:23 PM.
-
Prid - Outing
Actionscript Code:
quizItems[i]=new QuizItem(questionNode.firstChild.nodeValue);
You are calling QuizItem function BEFORE updating wrongresponse with the value fetched from the XML file, hence the first node is 'undefined', and the second one is equals to the first one's wrong response.
To solve this, add a new parameter to QuizItem:
Actionscript Code:
function QuizItem(question, wrong_response)
and then change, this.wrongresponse=wrongreponse; to this:
Actionscript Code:
this.wrongresponse=wrong_response;
then find this line:
Code:
quizItems[i]=new QuizItem(questionNode.firstChild.nodeValue);
and change it to this:
Actionscript Code:
quizItems[i]=new QuizItem(questionNode.firstChild.nodeValue, itemNode.childNodes[5].firstChild.nodeValue);
and lastly, just remove this line:
Code:
wrongresponse=itemNode.childNodes[5].firstChild.nodeValue;
I am back, guys ... and finally 18 :P
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
-
WORKS GREAT!!!! as always thank you so much, I owe you! and thanks for showing what I did wrong.
Adam
-
I have one more question, how can I get the "userScore" value (or final total score in percent) to only show the 100th place? right now I am getting answers like 33.3333333 like for it to show 33.33
-
Prid - Outing
Actionscript Code:
userScore = Math.floor(userScore*100)/100;
userScore*100 = 33.3333333*100 = 3333.33333
Math.floor(3333.33333) = 3333
3333/100 = 33.33
No problem
I am back, guys ... and finally 18 :P
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
-
I tried that and it doesn't work. tried Math.round as well.
I just noticed that the first thime you go through the quiz it returns bad results for questions answered correctly and questions answered and of course the Total or userScore. If you click play Adain button and go through again the results are good. fine. Must be another tiing issue
-
updated FLA and actually probably best to remove all decimal places and round off as whole number. Hopefully I will have a cleared head in the morning and figure this out.
Last edited by ADVaughn; 05-18-2012 at 01:24 PM.
-
Prid - Outing
It's working just fine here, the rounding that is and also no problems with answering questions...
I am back, guys ... and finally 18 :P
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
-
I wish, if you run the quiz and answer A for every question at the end it returns 5 correct and 7 incorrect, it should be 4 and 6, also you will notice it returns 66.66% there are 10 questions and it should be 40%. The strange thing is if you hit Play again and answer all A again this time it gives the Right Correct and incorrect answer count. But still retuns 66.66%.
Thanks for the reply and interest. I am an artist if you ever need a logo or something hit me up.
Adam
-
Prid - Outing
Maybe because in Frame 21 you have this:
Actionscript Code:
numOfQuestionsAnsweredCorrectly++;
and in Frame 23, this:
Actionscript Code:
numOfQuestionsAnsweredIncorrectly++;
which increases the incorrect and correct answer text by one (4 and 6 => 5 and 7). From what I see, you haven't made this yourself but have downloaded a template, or? If that's the case, I strongly advice you to create your own from scratch and you'll definitely have a better understanding of the coding, because the coding right now is really messy...
I am back, guys ... and finally 18 :P
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
-
actually it was something I made it a long time ago MX I think and am trying to make some changes for a friend of mine. Most of the time I am the guy creating the assets.
Without those values are not saved,
Last edited by ADVaughn; 05-17-2012 at 06:58 PM.
-
Prid - Outing
Aha, sorry about that 
If I look at my coding after a while after coding it, I'll have no idea what I had done and would have a hard time understanding it, as if reading someone else's code, and if you made a long time ago, then you've definitely forgotten the understanding, so I still advice you to write a new code, as it's relatively easy and fun
I am back, guys ... and finally 18 :P
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
-
took your advise and slowly rebuilt..... working fine now. Thanks again for all your help.
-
Prid - Outing
Nice
I am back, guys ... and finally 18 :P
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|