?
Solved

AS2 Flash MS Acess and a Randomize Quiz

Posted on 2012-04-12
16
Medium Priority
?
432 Views
Last Modified: 2012-04-26
I recently built a 4 question quiz which pulls all information from an Access database to populate 4 buttons as the answers and a dynamic label for the question. There are also several sections of the quiz so when the user ends a section they are presented with a small test of the previous questions. The program consists of several screens including an introduction screen, a message screen which the student is presented which relates to the previous question. There is also a correct screen and a wrong screen. As long as the student answers the question correctly they are moved onto the next question, however, if they get it wrong they are presented with a back button to get a refresher message about the question andthen the 4 questions.

The problem is that I am using an array from the onset to populate the four questions. As long as the answers are not randomized everything works perfectly. However, I randomize the questions by using an on (press) on the wrong button. This then populates the answers to the question with random answers. The only way I know how to populate the question screen is with the original array. I use a new array to populate the randomized answers  so the questions go back to the beginning question instead of the next question in that array...

Any help would be great...
0
Comment
Question by:baxters80
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 7
16 Comments
 
LVL 37

Accepted Solution

by:
CyanBlue earned 2000 total points
ID: 37837565
The simplest(and somewhat lazy if I may say) way I can think of is to make the correct/incorrect flag as a part of the answer.

For example, you might have something like this in your database right now.
quizID: 1
question: What is ABC blah blah?
answer1: abcd
answer2: efgh
answer3: ijkl
answer4: mnop
correct: 2

Open in new window

Instead, you can make it something like this.
quizID: 1
question: What is ABC blah blah?
answer1: 0|abcd
answer2: 1|efgh
answer3: 0|ijkl
answer4: 0|mnop

Open in new window

When you shuffle the answer array, the correct/incorrect flag stays with the answer this way.  All you need to do is to take '0|' or '1|' part out of the answer data and use it to detect if it is the correct answer or not, and display the answer without that data by using simple split() call.

CyanBlue
0
 

Author Comment

by:baxters80
ID: 37837692
Thank you, I am going to try that right now...
0
 

Author Comment

by:baxters80
ID: 37837718
Now that I think about it that is not the issue. I am actually comparing string to string...
The issue is that when I get a wrong response it resets the array and takes the user back to the first section...

For example...

section        question.......ans1......ans2.....ans3.....ans 4
1                      xxxx                a               b              c            d
1
1
1
2
2
2
2
3
3
3
3
4
4
4
4

Now from this table I create an array with the question, answer, and sections...As long as th euser gets the answer correct they are moved onto the next question in that section.

The problem is that if they get one wrong the array is reset and the next question is the first question of the first section...

As i stated, if the questions are not randomized it works fine..
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 37

Expert Comment

by:CyanBlue
ID: 37838534
Sorry, I fail to understand what the question is.  :(
The problem is that if they get one wrong the array is reset and the next question is the first question of the first section...

Open in new window

What is problem with that and how should it be treated in that case?

CyanBlue
0
 

Author Comment

by:baxters80
ID: 37838799
If the question is answered incorrectly it should go back and ask that same question again. The issue is that the array is reset and goes back to the very first question of the first section. So if the user is at question 3 of section 4 and they answer that question incorrectly the array is reset and the next question goes to question 1 of section 1.

Thank you for all of your help...
0
 

Author Comment

by:baxters80
ID: 37838838
Here is some more info...When the quiz begins an access database is queried which than populates an array which includes questions,answers, and section numbers.

The first question included 4 buttons which are the answers...These questions are populated by loading a a function which creates the array...As long as the questions are answered correctly they are fine. The issue is that once a answer is answered incorrectly the next set of answers from that question need to be randomized. I am not sure how to randomize the current array. So, when the question is answered incorrectly the function to load the answers is triggered again which than causes a new array to be generated...
0
 
LVL 37

Expert Comment

by:CyanBlue
ID: 37838938
If it is a matter of displaying the question that you have gotten wrong after you randomize the quiz questions, why not do this?

User gets the question wrong.
You get the id of the question.
Randomize the current array.
Loop through that array and pop the question with the given id into a new array.
Add that array item from the new array into the beginning of the randomized array.

That way you just need to display the first question to go back to your previous question?

CyanBlue
0
 

Author Comment

by:baxters80
ID: 37839370
I guess that is the problem, I am having problems randomizing the current array...I am not sure how to go about doing that...Currently the application loads a new array and then randomizes. that...If you could guide me in the right direction as to how to randomize the array that would be great....Actually there are four arrays one for each button...But once I know how to randomize an existing array I think I should be good..

Again, thank you....
0
 
LVL 37

Expert Comment

by:CyanBlue
ID: 37839698
Did a quick google and it seems that this one should do the job for you.
   http://mrsteel.wordpress.com/2007/06/15/randomize-array-shuffle-an-array-in-flash/

CyanBlue
0
 

Author Comment

by:baxters80
ID: 37840079
I had already seen this link....
I just cant seem to find any info on taking 3 existing arrays and creating a new one from that array.

Array 1= Answer Column 1
Array 2=Answer Column 2
Array 3= Answer Column 3

I need to create 3 new arrays from the existing arrays(above) so that I can than randomize them.
I can than loop through the three new arrays to populate the answers...
0
 
LVL 37

Expert Comment

by:CyanBlue
ID: 37840161
I know you are trying hard to explain the problem, but whatever you said just lost me.

Do yourself a favor and create a standalone example that you are trying to randomize and maybe I can help with that.

CyanBlue
0
 

Author Comment

by:baxters80
ID: 37840778
Ok, so here it goes....

I have attached an example...

When the application is executed 3 arrays are created
Response1
Response2
Reponse3

So each option is its own array...

Each array is than randomized for each question which is looped through to populate the answers....

For example....

Array Response 1[x,c,z,c,r,a]
Array Response 2[a,g,e,r,t,b]
Array Response 3[b,e,f,s,r,c]
I do not push answer 4 into an array because answer 4 is alway "all of the above"

Now, as I loop through the array

What is this?
1.x
2.a
3.b


Question 2
What is that
1.c
2 g
3 e

Question 3
How are you
1. z
2. e
3. f

And so on.....

As long as the responses are correct the user is moved onto the next question...

Now, if the response is wrong the user is brought back to the question again and the responses are randomized...The issue is that currently a new array is generated each time the answers are randomized. SO once a wrong response is given the questions go back to the beginning Question1 Section 1...

I need to be able to randomize the existing array without querying the database and generating a new array and I am not sure how to go about it...
example.xls
0
 
LVL 37

Expert Comment

by:CyanBlue
ID: 37842595
When I said example, I meant ActionScript example that shows your problem. I don't need to go through all those you have up there if I can help you shuffle the array, do I?

CyanBlue
0
 

Author Comment

by:baxters80
ID: 37842943
Ok, here it goes

LoadSection.asp is the file that loads the data from the database...This script is used to generate the first array. The arrays that are generated are option1,option2,option3...

Now the attached file is the AS2 code that I use to generate the new arrays. As you can see a new LoadSetion.asp is executed thus new arrays are created. So, when the user gets the first question wrong they are taken back to Question1 and Section1...

I need to be able to randomize Option1, Option2, and Option3 from the original arrays instead of creating new ones...

Thank you for all of your help...
randomAS2.txt
0
 

Author Comment

by:baxters80
ID: 37843511
I thought I had it, however, the items display but are not randomized...
var sections = [option1];
var randomSection = sections[Math.floor((Math.random()*sections.length))];
trace ("randomSection" + randomSection[current]);
trace ("randomSection" + randomSection[current]);
trace ("randomSection" + randomSection[current]);

var sections2 = [option2];
var randomSection2 = sections2[Math.floor((Math.random()*sections.length))];
trace ("randomSection2" + randomSection2);

                              
                              var sections3 = [option3];
var randomSection3 = sections3[Math.floor((Math.random()*sections.length))];
trace ("randomSection3" + randomSection3);
0
 
LVL 37

Expert Comment

by:CyanBlue
ID: 37843822
Now I feel like I am a bully but I'll have to say this one last time because I can help you only if you can help me help you.

I want you create a simple test case which shows three arrays with their values filled with test values, do appropriate randomization process. and traces out the results.
Here is some more information on what a test case should do if you want to read more about it.
   http://www.faqs.org/qa/qa-6667.html

I want to copy that script and past it into Flash to test it and possibly help you but I don't want to look at your datasets because we all know that that's not where the problem is.  

Hopefully this test case will help me understand what your problem is in the script cuz I couldn't identify that part yet.

CyanBlue
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question