0 Replies - 3254 Views - Last Post: 09 November 2012 - 10:04 AM

#1 techbits  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 09-November 12

how to reset this drag and drop button

Posted 09 November 2012 - 10:04 AM

Could you help me solve this. I have been stuck with this reset function for days.

I want to make this drag and drop function as it first run. I had try to reset it back by reset the frame but it finally turns to the first frame while it's actually the fifth frame.

Then I had try to call the addeventlistener back and initialize the position back. But it seems to never work at all. Could anybody help me with this asap. Sorry this is the first time i'm using flash.

stop();

var xPos:int;
var yPos:int;
var xPosK:int;
var yPosK:int;
nextbtn.visible=false;
		
ndragbtn.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag_3);
ndragbtn.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop_3);

kdragbtn.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag_4);
kdragbtn.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop_4);

submitbtn.addEventListener(MouseEvent.CLICK, submit);
nextbtn.addEventListener(MouseEvent.CLICK, nextrandom);
homebtn.addEventListener(MouseEvent.CLICK, home);


		
function getPosition(ndragbtn):void
		{
			xPos = ndragbtn.x;
			yPos = ndragbtn.y;
		}

function getPosition1(kdragbtn):void
		{
			xPosK = kdragbtn.x;
			yPosK = kdragbtn.y;
		}

function fl_ClickToDrag_3(event:MouseEvent):void
{
	getPosition(ndragbtn);
	ndragbtn.startDrag();
}

function fl_ClickToDrag_4(event:MouseEvent):void
{
	getPosition1(kdragbtn);
	kdragbtn.startDrag();
}

function fl_ReleaseToDrop_3(event:MouseEvent):void
{
	
	
	if (ndragbtn.hitTestObject(ndragbtnTarget))
			{
		ndragbtn.x = ndragbtnTarget.x;
		ndragbtn.y = ndragbtnTarget.y;
		ndragbtnTarget=ndragbtn;
		}
	
	else if(ndragbtn.hitTestObject(kdragbtnTarget))
	 {
		 ndragbtn.x = kdragbtnTarget.x;
		 ndragbtn.y = kdragbtnTarget.y;
		 kdragbtnTarget=ndragbtn;
		 }

	ndragbtn.stopDrag();
	kdragbtn.stopDrag();
}

function fl_ReleaseToDrop_4(event:MouseEvent):void
{
	
	
	if (kdragbtn.hitTestObject(kdragbtnTarget))
			{
		kdragbtn.x = kdragbtnTarget.x;
		kdragbtn.y = kdragbtnTarget.y;
		kdragbtnTarget=kdragbtn;
		}
	 else if(kdragbtn.hitTestObject(ndragbtnTarget))
	 {
		 kdragbtn.x = ndragbtnTarget.x;
		 kdragbtn.y = ndragbtnTarget.y;
		 ndragbtnTarget=kdragbtn;
		 }
	
	kdragbtn.stopDrag();
	ndragbtn.stopDrag();
}

function submit(event:MouseEvent):void
{
	
 if(ndragbtn == ndragbtnTarget && kdragbtn == kdragbtnTarget)
 {
	 statustxt.text="Correct and you can proceed!";
	 nextbtn.visible=true;
	 }
	 else{
		 statustxt.text="Sorry please try again!";
		 ndragbtn.x = xPos;
		 ndragbtn.y = yPos;
		 kdragbtn.x = xPosK;
		 kdragbtn.y = yPosK;
		
		 //resetAll(); HOW TO RESETTTTTT!!!!!!!!!!!!!!!!!!!!!
		 
		 }
		 
}




Is This A Good Question/Topic? 0
  • +

Page 1 of 1