Skip to main content
Known Participant
March 10, 2011
Question

hitTestObject AND THEN snap back to original place?

  • March 10, 2011
  • 3 replies
  • 592 views

THOUGHT THIS WOULD SNAP (choice_1) BACK INTO PLACE AFTER HITTING TEST OBJECT. WHAT DID I DO WRONG?


import flash.net.URLVariables;
import flash.net.URLRequest;

var origX:Number;
var origY:Number;

/* Drag and Drop
Makes the specified symbol instance moveable with drag and drop.
*/
origX = x;
origY = y;

choice_1.buttonMode = true;
choice_1.mouseChildren = false;
choice_1.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag);

function fl_ClickToDrag(event:MouseEvent):void
{
choice_1.startDrag();
}

stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);

function fl_ReleaseToDrop(event:MouseEvent):void
{
choice_1.stopDrag();

if(choice_1.hitTestObject(box_1))
{
box_1.text = choice_1.text;
}

x = origX;
y = origY;
}

This topic has been closed for replies.

3 replies

Known Participant
March 10, 2011

I need to do this 5 times.  Is there anyway to make origX unique?

Ned Murphy
Legend
March 10, 2011

It's not clear what you mean in saying you need to do it 5 times.  As it stands, origX is unique... it only identifies the starting position of choice_1.

Known Participant
March 10, 2011

Awesome Ned! Thanks so much! Did the trick! Brilliant!!!

Ned Murphy
Legend
March 10, 2011

See if using the x properties of the object you are dragging helps...

origX = choice_1.x;
origY = choice_1.y;

and later...

choice_1.x = origX;

choice_1.y = origY;