FORUMS: list search recent posts

Reset objects in a drag and drop game

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Ben Fisher
Reset objects in a drag and drop game
on Jan 25, 2010 at 8:19:02 am

i am following a tutorial to create a game where you drag pictures of Egyptian gods to match them with their name. when all the images are matched, it goes to the second frame which tells the user they have finished. i want to add a button which would allow the user to play again, but i need to reset all the objects first. how do i do that?

here's the code i've got:

var score:Number = 0;
var objectoriginalX:Number;
var objectoriginalY:Number;
thoth_mc.buttonMode=true;
thoth_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
thoth_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
sobek_mc.buttonMode=true;
sobek_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
sobek_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
ptah_mc.buttonMode=true;
ptah_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
ptah_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
sekhmet_mc.buttonMode=true;
sekhmet_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
sekhmet_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
function pickupObject(event:MouseEvent):void {
event.target.startDrag(true);
event.target.parent.addChild(event.target);
objectoriginalX=event.target.x;
objectoriginalY=event.target.y;
response_txt.text=" ";
}
function dropObject(event:MouseEvent):void {
event.target.stopDrag();
var matchingTargetName:String="target"+event.target.name;
var matchingTarget:DisplayObject=getChildByName(matchingTargetName);
if (event.target.dropTarget!=null&&event.target.dropTarget.parent==matchingTarget) {
event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
event.target.removeEventListener(MouseEvent.MOUSE_UP, dropObject);
event.target.buttonMode=false;
event.target.x=matchingTarget.x;
event.target.y=matchingTarget.y;
response_txt.text="Great!";
score++;
score_txt.text = String(score);
} else {
event.target.x=objectoriginalX;
event.target.y=objectoriginalY;
response_txt.text="Try Again";
}
if (score == 4){
gotoAndPlay(2);
}
}


huge thanks in advance,
ben


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]