I found this script for dragging shapes to target shapes for drag and drop. But, I would like the original shapes to stay in their original position and the copies to be dragged to their targets. This would leave behind the originals which could again be dragged to the targets and so on. There would be multiple shapes. Can someone show me how to change this code to add duplication of the shapes when dragged? Also, if the shape dragged is not dragged on the matching target shape then the shape should be deleted from the stage.
TIA
package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
public class Main extends Sprite
{
var xPos:int;
var yPos:int;
public function Main():void
{
addListeners(square, triangle, circle);
}
private function getPosition(target:Object):void
{
xPos = target.x;
yPos = target.y;
}
private function dragObject(e:MouseEvent):void
{
getPosition(e.target);
e.target.startDrag(true);
}
private function stopDragObject(e:MouseEvent):void
{
if (e.target.hitTestObject(getChildByName(e.target.name + "Target")))
{
e.target.x = getChildByName(e.target.name + "Target").x;
e.target.y = getChildByName(e.target.name + "Target").y;
}
else
{
e.target.x = xPos;
e.target.y = yPos;
}
e.target.stopDrag();
}
private function addListeners(... objects):void
{
for (var i:int = 0; i < objects.length; i++)
{
objects*.addEventListener(MouseEvent.MOUSE_DOWN, dragObject);
objects*.addEventListener(MouseEvent.MOUSE_UP, stopDragObject);
}
}
}
}