Copy link to clipboard
Copied
Hello,
I need help. I wanna create a simple drag and drop quiz with score. The quiz contains 5 questions and you answer the questions with drag and drop method. Questions are not random and each question is on one frame. I don't use XML either for the questions or the answers, I just typed it as static text for the question and Movie Clips for the answer. The score is displayed when you answer the last question, and is on frame 6. And now, I have been searching the code for the scoring system without XML, but I don't find what I need. I am new with flash so I have no idea how to create a scoring system without XML. Do you know if there's a way to create a scoring system without XML? And how?
Thankyou
Copy link to clipboard
Copied
It sounds like you're working in an Actionscript file. Regardless, you should be able to keep everything that you need in variables. I have no idea how you are scoring your questions, so I can't tell you how to do the actual scoring. If each possible answer is a unique movieClip with a unique instance name, then you could put the name of the correct clip into a variable and then compare the selected clip's name against the value in the variable. Create a separate variable to hold the score value. If the answer is correct increment the value in the score variable. At frame 6 just set the contents of a dynamic textField to the value in the score variable.
Copy link to clipboard
Copied
here is the code:
right_mc.visible=false;
wrong_mc.visible=false;
oke_btn.visible=false;
var orig1X:Number=image1.x;
var orig1Y:Number=image1.y;
var orig2X:Number=image2.x;
var orig2Y:Number=image2.y;
var orig3X:Number=image3.x;
var orig3Y:Number=image3.y;
var orig4X:Number=image4.x;
var orig4Y:Number=image4.y;
image1.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);
image1.addEventListener(MouseEvent.MOUSE_UP, image1Release);
image2.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);
image2.addEventListener(MouseEvent.MOUSE_UP, image2Release);
image3.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);
image3.addEventListener(MouseEvent.MOUSE_UP, image3Release);
image4.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);
image4.addEventListener(MouseEvent.MOUSE_UP, image4Release);
image1.buttonMode=true;
image2.buttonMode=true;
image3.buttonMode=true;
image4.buttonMode=true;
function dragTheObject(event:MouseEvent):void {
var item:MovieClip=MovieClip(event.target);
item.startDrag();
var topPos:uint=this.numChildren-1;
this.setChildIndex(item, topPos);
}
function image1Release(event:MouseEvent):void {
var item:MovieClip=MovieClip(event.target);
item.stopDrag();
if (dropbox.hitTestPoint(item.x,item.y)) {
item.x=dropbox.x;
item.y=dropbox.y;
} else {
item.x=orig1X;
item.y=orig1Y;
}
}
function image2Release(event:MouseEvent):void {
var item:MovieClip=MovieClip(event.target);
item.stopDrag();
if (dropbox.hitTestPoint(item.x,item.y)) {
item.x=dropbox.x;
item.y=dropbox.y;
} else {
item.x=orig2X;
item.y=orig2Y;
}
}
function image3Release(event:MouseEvent):void {
var item:MovieClip=MovieClip(event.target);
item.stopDrag();
if (dropbox.hitTestPoint(item.x,item.y)) {
item.x=dropbox.x;
item.y=dropbox.y;
} else {
item.x=orig3X;
item.y=orig3Y;
}
}
function image4Release(event:MouseEvent):void {
var item:MovieClip=MovieClip(event.target);
item.stopDrag();
if (dropbox.hitTestPoint(item.x,item.y)) {
item.x=dropbox.x;
item.y=dropbox.y;
} else {
item.x=orig4X;
item.y=orig4Y;
}
}
next_btn.addEventListener(MouseEvent.CLICK,checkAnswers);
function checkAnswers(event:MouseEvent):void {
if (dropbox.hitTestPoint(image1.x-50,image1.y-50)){
wrong_mc.visible = false;
right_mc.visible = true;
oke_btn.visible = true;
image1.visible=false;
image2.visible=false;
image3.visible=false;
image4.visible=false;
} else {
wrong_mc.visible = true;
right_mc.visible = false;
oke_btn.visible = true;
image1.visible=false;
image2.visible=false;
image3.visible=false;
image4.visible=false;
}
}
oke_btn.addEventListener(MouseEvent.CLICK, oke);
function oke(event:MouseEvent):void {
gotoAndStop(2,"Quiz");
}
I'm sorry but could you please tell me the right way to do what you have told me?
Thankyou so much
Copy link to clipboard
Copied
To simply answer your question about evaluating the user's answer: you're already doing that at each of the imageXRelease functions. If the hitTest is true then the answer is correct. So, you can just increment your score variable. Maybe something like this:
var userScore:Number = 0; // put this at the top of the code in frame 1.
then in each imageXRelease function add: userScore ++ to this section:
if (dropbox.hitTestPoint(item.x,item.y)) {
item.x=dropbox.x;
item.y=dropbox.y;
But there are so many other things that I don't understand about your code.
1. Is each drag and drop question in a separate frame?
2. If so, how are you moving from frame to frame?
3. If all of this code is on frame 1 then are all of the draggable objects and their targets on the stage but hidden until needed?
You might want to Google: drag and drop game actionscript 3. You will find a long list of examples that should meet your needs.
Copy link to clipboard
Copied
I have done something like that, but it didn't work for me.
And for your questions,
1. Yes, it is in a separate frame. One drag and drop question is on one frame.
2. When I click "next_btn" button, then a simple notification displayed for telling me if I answered the question correctly or not. The notification displayed with "oke_btn" button. The "oke_btn" will bring me to the next frame.
3. Yes, all of this code is on one frame. I just want them removed when I move to the next frame, because when I didn't set them visible=false, they move along to the next frame. Or should I change it to removeChild(image1)?
Yeah I learned this drag and drop code from google.
And here's the file if you wanna see the program: quiz.fla - Google Drive
Inside that file only has 3 frames, 2 for questions and 1 for scoring display. It's just for an example because the original is not in english .
Copy link to clipboard
Copied
you don't need xml.
but the question is if you need some sort of database and server-side code. the answer depends on whether you want users to compete against each other. if yes, you need server-side code/database. if no, you don't.
Copy link to clipboard
Copied
I have done something like that, but it didn't work for me.
And for your questions,
1. Yes, it is in a separate frame. One drag and drop question is on one frame.
2. When I click "next_btn" button, then a simple notification displayed for telling me if I answered the question correctly or not. The notification displayed with "oke_btn" button. The "oke_btn" will bring me to the next frame.
3. Yes, all of this code is on one frame. I just want them removed when I move to the next frame, because when I didn't set them visible=false, they move along to the next frame. Or should I change it to removeChild(image1)?
Yeah I learned this drag and drop code from google.
Copy link to clipboard
Copied
I don't know what I can do for you. I could build your project for you, but that's outside the scope of this forum. Most questions in this forum cover one specific problem with some descriptive information about that problem. I replied to your general question with a general reply. I replied to your specific question with a specific reply. "I have done something like that, but it didn't work for me.", isn't a useful response.
It's very difficult to guess how your example code might be used. There is no context. There is no explanation of the procedure that you are using the the quiz. There is no commenting in the code.
Copy link to clipboard
Copied
OK, so the first version of your followup did not contain the link to your file, apparently because the followup was being moderated. So most of my response above will make no sense to you. I have no idea why this happens, I guess it's just another feature of the forum software. I'm sorry if I've caused you any undue stress with my answer above.
In your first question, the one about the chicken heads, you have two items that need to be matched. You will need to allow each of the correct heads to be dragged to either of the drop boxes. Right now if you put the fourth head into the first target and the first head into the second target, you give a wrong answer. It might be better to just allow the user to select the correct heads without dragging them to a particular target. This same method might also be applied the subsequent questions, dragging the correct item to a target doesn't enhance the experience, it just complicates it. But that is just my opinion.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now