Hi guys,
I’m currently trying to work on a quick drag and drop flash game. I have all the basics down so far which is as follows:
You start with 3 objects, and 3 target categories. You need to place the object in to the corresponding target zone. In this case it’s placing the gas, liquid or solid element into the correct category shown.
I have everything working so far so it locks in to place if placed correct, a counter to enable a congratulations message when completed and the object to snap back in to place if the object is placed in an incorrect position.
I’m just trying to get my head round how to create a button so that on press it resets the .swf back to it’s original state (I’ve been following tutorials if you hadn’t guessed :p).
I’d also like to eventually have more than 3 objects so I could place several ‘solids’ into the one category target for example. Although the code I’m using doesn’t seem to support this.
Any help is greatly appreciated.
Here’s the code I have:
var counter:Number = 0;
var startX:Number;
var startY:Number;
gas_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
gas_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
liquid_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
liquid_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
solid_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
solid_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
function pickUp(event:MouseEvent):void {
event.target.startDrag(true);
reply_txt.text = "";
event.target.parent.addChild(event.target);
startX = event.target.x;
startY = event.target.y;
}
function dropIt(event:MouseEvent):void {
event.target.stopDrag();
var myTargetName:String = "target" + event.target.name;
var myTarget:DisplayObject = getChildByName(myTargetName);
if (event.target.dropTarget != null && event.target.dropTarget.parent == myTarget){
reply_txt.text = "wel dun m8!";
event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickUp);
event.target.removeEventListener(MouseEvent.MOUSE_UP, dropIt);
event.target.buttonMode = false;
counter++;
} else {
reply_txt.text = "u fail";
event.target.x = startX;
event.target.y = startY;
}
if(counter == 3){
reply_txt.text = "omg u did it, i r prowd of u!!!1";
}
}
solid_mc.buttonMode = true;
gas_mc.buttonMode = true;
liquid_mc.buttonMode = true;