Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 07-13-2007, 02:56 AM   #1
suriaz20
Registered User
 
Join Date: Jun 2006
Posts: 3
Unhappy [AS2] How to Keep & Display score for Drag & Drop Game??

I need your kind help urgently.

I need to create a simple drag and drop game. If the object is dropped to the correct location, the score will be displayed (e.g. 3 out of 4 right!).

I managed to create the drag and drop and snapped it at the right location.

But, am unable to keep and display the score.

I have minimal AS knowledge so the code below was taken from other sites. (I do know the meaning of instance names, and some basic actions though)

Anyone can help?????
-------------------------------------------------------------------------
This is my actionscript applied for the object called "paper" -

onClipEvent (load) {
origX = this._x;
origY = this._y;
}

onClipEvent (mouseDown) {
if (this.hitTest(_root._xmouse, _root._ymouse)) {
this.startDrag();
}
}
onClipEvent (mouseUp) {
if (this.hitTest(_root._xmouse, _root._ymouse)) {
this.stopDrag();
}
// see if the dropZone contains the center of this mc
if (_parent.plastic.hitTest(this._x,this._y,true)) {

// center it on the drop zone
this._x = _parent.plastic._x;
this._y = _parent.plastic._y;

// this part here, I did on my own...just an assumption that it might
work but didn't

var total=1;
total++;
score.text="You scored " + total +" out of 4";

}
else {
// return it to its original location
this._x = origX;
this._y = origY;
}

}

Last edited by suriaz20; 07-13-2007 at 03:02 AM.
suriaz20 is offline   Reply With Quote
Old 07-13-2007, 01:27 PM   #2
Noct
Toys in the Attic...
 
Noct's Avatar
 
Join Date: Oct 2006
Location: NY
Posts: 3,022
Default

Welcome aboard,
Try this: (untested)
ActionScript Code:
onClipEvent (load) {     var origX:Number = this._x;     var origY:Number = this._y;     var total:Number = 0;     var dZ:MovieClip = this._parent.plastic; } on (press) {     this.startDrag(); } on (release) {     this.stopDrag();     // see if the dropZone contains the center of this mc      if (this.hitTest(dZ)) {         // center it on the drop zone         this._x = dZ._x+dZ._width/2-(this._width/2);         this._y = dZ._y+dZ._height/2-(this._height/2);         total++;         this._parent.score.text = "You scored "+total+" out of 4";     } else {         // return it to its original location         this._x = origX;         this._y = origY;     } }

Oh, and if you don't want the user to be able to drag the same clip again, stick a disable script on the line below this._parent.score.text = "You scored "+total+" out of 4";"
ActionScript Code:
this.enabled=false
__________________
http://rwithers.com

Last edited by Noct; 07-13-2007 at 01:32 PM.
Noct is offline   Reply With Quote
Old 07-16-2007, 08:59 AM   #3
suriaz20
Registered User
 
Join Date: Jun 2006
Posts: 3
Smile Thanks!

Thanks!!!

Your code looks much simpler to understand and it works flawlessly!
suriaz20 is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Flash game with PHP/MySQL - score faking problem Danko Gaming and Game Development 0 10-10-2005 10:09 AM
script help for drag and drop type game creations Gaming and Game Development 2 09-13-2005 05:46 PM
Game - freelancer required fatherb Projects and Positions 6 07-18-2003 11:47 AM
Starttrek Game - Bug with Highscore - please help bullys2003 Server-Side Scripting 5 03-30-2003 01:06 PM
How do I display a score of zero? Bullfrog ActionScript 1.0 (and below) 2 05-06-2002 08:57 PM


All times are GMT. The time now is 02:02 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.