Skip to main content
Participating Frequently
January 11, 2017
Question

score counter in drag and drop game

  • January 11, 2017
  • 1 reply
  • 2097 views

i want to make a drag and drop flash game using AS3. i want each correct dropped item to worth one point and after the learner makes the series of drops and clicks "submit" , his score will show at the end. how to make the score counter in that case?

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
January 11, 2017

create a variable whose value records the score:

var score:int = 0; // initialize

and in your drop functions:

if(whatever dropTarget == expected target){

score++;

}

function submit_listener(e:MouseEvent):void{

score_tf.text="your score is "+score.toString();

}

Participating Frequently
January 20, 2017

access of undefined property score_tf ????

Participating Frequently
January 20, 2017

i don't see where you're using a submit click any more so use:

var offset:int = 30;

var score:int = 0; // initialize

var wa1StartX:int = 43;

var wa1StartY:int = 44;

var wa1EndX:int = 405;

var wa1EndY:int = 190;

wa1.buttonMode = true;

wa1.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);

wa1.addEventListener(MouseEvent.MOUSE_UP, stopDragging);

function startDragging(event:MouseEvent):void {

event.currentTarget.startDrag();

}

function stopDragging(event:MouseEvent):void {

event.currentTarget.stopDrag();

switch (event.currentTarget) {

case wa1:

if (wa1.x < wa1EndX - offset || wa1.x > wa1EndX + offset || wa1.y < wa1EndY - offset || wa1.y > wa1EndY + offset) {

wa1.x = wa1StartX;

wa1.y = wa1StartY;

} else {

wa1.x = wa1EndX;

wa1.y = wa1EndY;

}

}

if(wa1.x == wa1EndX){

score++;

updateDisplayF();

}

}

function updateDisplayF():void{

score_tf.text="your score is "+score.toString();

}


YOU ARE THE BEST! THANKS!