Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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();
}
Copy link to clipboard
Copied
i want the answer in more details because i am a beginner
Copy link to clipboard
Copied
copy and paste the listener function called when objects are dropped.
Copy link to clipboard
Copied
access of undefined property score_tf ????
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
you call submit_listener(null) whenever you want to update that textfield.
Copy link to clipboard
Copied
here is the script please tell me whats wrong
Copy link to clipboard
Copied
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();
}
}
Copy link to clipboard
Copied
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();
}
Copy link to clipboard
Copied
YOU ARE THE BEST! THANKS!
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now