Hi there,
I’m currently working on a little project which involves dragging and dropping options into the relevant box, checking the answer and providing the user with a score at the end of it.
So far I have worked out the drag and drop of six elements which can be dragged across the stage. I have also managed to get the ActionScript to recognise when “item1” appears to clash with “area1” via a HitTest.
These are the problems I have come across now:
[LIST]
[]Duplicating the drag and drop HitTest for all of the other five elements.
[]I’m also having problems with keeping a score of this (i.e. when “item1” matches “area1” it gives a score of +1 and so on) and instead I am getting a continuous +1. I can completely understand why this is happening but am unsure how to fix it.
[/LIST]Below is the Actionscript code I have so far:
var score
score = 0; /* sets score to zero */
item1.addEventListener(MouseEvent.MOUSE_DOWN, drag);
item2.addEventListener(MouseEvent.MOUSE_DOWN, drag);
item3.addEventListener(MouseEvent.MOUSE_DOWN, drag);
item4.addEventListener(MouseEvent.MOUSE_DOWN, drag);
item5.addEventListener(MouseEvent.MOUSE_DOWN, drag);
item6.addEventListener(MouseEvent.MOUSE_DOWN, drag);
stage.addEventListener(MouseEvent.MOUSE_UP, drop);
function drag(e:MouseEvent):void
{
e.target.startDrag(false, new Rectangle(0,0,465,450));
}
function drop(e:MouseEvent):void
{
stopDrag();
}
area1.addEventListener(Event.ENTER_FRAME,checkHitTest);
/* hit test for item 1 */
function checkHitTest(event:Event){
if(item1.hitTestObject(area1))
{
statusTxt.text = "Item 1 is in the correct place!";
score = score + 1;
}
else{
statusTxt.text = "That's wrong!";
}
scoreDisplay.text = score;
}
Also if you would like to see what I have so far in the FLA file please see the attached.
If anyone could be of any help I would be very grateful.
Cheers,
KugarWeb