# Drag and drop then SNAP BACK TO ORIGIN → URGENT HELP PLEASE

**URL:** <https://forum.kirupa.com/t/drag-and-drop-then-snap-back-to-origin-urgent-help-please/319986>\
**Category:** flash\
**Created:** [March 10, 2011, 2:56pm UTC](https://forum.kirupa.com/t/drag-and-drop-then-snap-back-to-origin-urgent-help-please/319986 "2011-03-10T14:56:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![arove](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@arove](https://forum.kirupa.com/u/arove)\
**Post date:** [March 10, 2011, 2:56pm UTC](https://forum.kirupa.com/t/drag-and-drop-then-snap-back-to-origin-urgent-help-please/319986/1 "2011-03-10T14:56:55Z")

</div>

THANKS FOR ANY HELP! 🙂

5 text choices (choice\_1 → choice\_5)  
5 text field targets (box\_1 → box\_5)

FUNCTION:

1. Drag the choices to the targets.
2. When dropped they display in target fields.
3. Then snap back.

I thought I had it but no cigar … must be close though.

Everything functions properly EXCEPT when I drag a choice and drop it all five choices go to choice\_5 (XY) instead of their own origin.

HOW DO I SOLVE THIS?

PROBLEM CAN BE SEEN HERE

[paintedthetown.com/draganddrop.php](http://paintedthetown.com/draganddrop.php)

[CODE]

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

var origX:Number;  
var origY:Number;

origX = choice\_1.x;  
origY = choice\_1.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;
}

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

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

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

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

```

choice\_1.x = origX;  
choice\_1.y = origY;  
}

// CHOICE 2

origX = choice\_2.x;  
origY = choice\_2.y;

choice\_2.buttonMode = true;  
choice\_2.mouseChildren = false;  
choice\_2.addEventListener(MouseEvent.MOUSE\_DOWN, fl\_ClickToDrag\_2);

function fl\_ClickToDrag\_2(event:MouseEvent):void  
{  
choice\_2.startDrag();  
}

stage.addEventListener(MouseEvent.MOUSE\_UP, fl\_ReleaseToDrop\_2);

function fl\_ReleaseToDrop\_2(event:MouseEvent):void  
{  
choice\_2.stopDrag();

```
if(choice_2.hitTestObject(box_1))
{
box_1.text = choice_2.text;
}

if(choice_2.hitTestObject(box_2))
{
box_2.text = choice_2.text;
}

if(choice_2.hitTestObject(box_3))
{
box_3.text = choice_2.text;
}

if(choice_2.hitTestObject(box_4))
{
box_4.text = choice_2.text;
}

if(choice_2.hitTestObject(box_5))
{
box_5.text = choice_2.text;
}

```

choice\_2.x = origX;  
choice\_2.y = origY;  
}

//CHOICE 3

origX = choice\_3.x;  
origY = choice\_3.y;

choice\_3.buttonMode = true;  
choice\_3.mouseChildren = false;  
choice\_3.addEventListener(MouseEvent.MOUSE\_DOWN, fl\_ClickToDrag\_3);

function fl\_ClickToDrag\_3(event:MouseEvent):void  
{  
choice\_3.startDrag();  
}

stage.addEventListener(MouseEvent.MOUSE\_UP, fl\_ReleaseToDrop\_3);

function fl\_ReleaseToDrop\_3(event:MouseEvent):void  
{  
choice\_3.stopDrag();

```
if(choice_3.hitTestObject(box_1))
{
box_1.text = choice_3.text;
}

if(choice_3.hitTestObject(box_2))
{
box_2.text = choice_3.text;
}

if(choice_3.hitTestObject(box_3))
{
box_3.text = choice_3.text;
}

if(choice_3.hitTestObject(box_4))
{
box_4.text = choice_3.text;
}

if(choice_3.hitTestObject(box_5))
{
box_5.text = choice_3.text;
}

```

choice\_3.x = origX;  
choice\_3.y = origY;  
}

// CHOICE 4

origX = choice\_4.x;  
origY = choice\_4.y;

choice\_4.buttonMode = true;  
choice\_4.mouseChildren = false;  
choice\_4.addEventListener(MouseEvent.MOUSE\_DOWN, fl\_ClickToDrag\_4);

function fl\_ClickToDrag\_4(event:MouseEvent):void  
{  
choice\_4.startDrag();  
}

stage.addEventListener(MouseEvent.MOUSE\_UP, fl\_ReleaseToDrop\_4);

function fl\_ReleaseToDrop\_4(event:MouseEvent):void  
{  
choice\_4.stopDrag();

```
if(choice_4.hitTestObject(box_1))
{
box_1.text = choice_4.text;
}

if(choice_4.hitTestObject(box_2))
{
box_2.text = choice_4.text;
}

if(choice_4.hitTestObject(box_3))
{
box_3.text = choice_4.text;
}

if(choice_4.hitTestObject(box_4))
{
box_4.text = choice_4.text;
}

if(choice_4.hitTestObject(box_5))
{
box_5.text = choice_4.text;
}

```

choice\_4.x = origX;  
choice\_4.y = origY;  
}

// CHOICE 5

origX = choice\_5.x;  
origY = choice\_5.y;

choice\_5.buttonMode = true;  
choice\_5.mouseChildren = false;  
choice\_5.addEventListener(MouseEvent.MOUSE\_DOWN, fl\_ClickToDrag\_5);

function fl\_ClickToDrag\_5(event:MouseEvent):void  
{  
choice\_5.startDrag();  
}

stage.addEventListener(MouseEvent.MOUSE\_UP, fl\_ReleaseToDrop\_5);

function fl\_ReleaseToDrop\_5(event:MouseEvent):void  
{  
choice\_5.stopDrag();

```
	if(choice_5.hitTestObject(box_1))
{
box_1.text = choice_5.text;
}

if(choice_5.hitTestObject(box_2))
{
box_2.text = choice_5.text;
}

if(choice_5.hitTestObject(box_3))
{
box_3.text = choice_5.text;
}

if(choice_5.hitTestObject(box_4))
{
box_4.text = choice_5.text;
}

if(choice_5.hitTestObject(box_5))
{
box_5.text = choice_5.text;
}

```

choice\_5.x = origX;  
choice\_5.y = origY;  
}

```auto

```
