Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

score counter in drag and drop game

New Here ,
Jan 11, 2017 Jan 11, 2017

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?

TOPICS
ActionScript
2.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 11, 2017 Jan 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();

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 14, 2017 Jan 14, 2017

i want the answer in more details because i am a beginner

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 14, 2017 Jan 14, 2017

copy and paste the listener function called when objects are dropped.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 20, 2017 Jan 20, 2017

access of undefined property score_tf ????

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 20, 2017 Jan 20, 2017

do you want to display the score in a textfield?

if yes, use that textfield instead of score_tf.  if not, remove that line of code.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 20, 2017 Jan 20, 2017

yes i want to display the score in a textfield. i created a text field and rename it score_tf but the score doesn't show in it. how to fix that?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 20, 2017 Jan 20, 2017

you call submit_listener(null) whenever you want to update that textfield.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 20, 2017 Jan 20, 2017

here is the script please tell me whats wrong

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 20, 2017 Jan 20, 2017

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++;

}

function submit_listener(e:MouseEvent):void{

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

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 20, 2017 Jan 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();

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 20, 2017 Jan 20, 2017

YOU ARE THE BEST! THANKS!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 20, 2017 Jan 20, 2017
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines