# Drag, duplicate and drop convert from as to as3

**URL:** <https://forum.kirupa.com/t/drag-duplicate-and-drop-convert-from-as-to-as3/327744>\
**Category:** Uncategorized\
**Created:** [March 25, 2012, 11:23pm UTC](https://forum.kirupa.com/t/drag-duplicate-and-drop-convert-from-as-to-as3/327744 "2012-03-25T23:23:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sebastian\_Soder](https://avatars.discourse-cdn.com/v4/letter/s/f08c70/32.png) [@Sebastian\_Soder](https://forum.kirupa.com/u/Sebastian_Soder)\
**Post date:** [March 25, 2012, 11:23pm UTC](https://forum.kirupa.com/t/drag-duplicate-and-drop-convert-from-as-to-as3/327744/1 "2012-03-25T23:23:16Z")

</div>

Hi I’m trying to create an drag, duplicate and drop program in flash and as3 but I can’t get it to work, I have this as2 code that works perfect but for as2 any one have a tip on how to convert it or can give me a hand ?

stop();

// the press action for gifts to be picked up and dragged  
function copyGiftForDrag(){  
// create a copy to be dragged (name same as linkage identifier)  
var position = {\_x: this.\_x, \_y: this.\_y};  
var copy = this.\_parent.attachMovie(this.\_name, this.\_name, 1, position);  
// drag the copy  
copy.startDrag();  
// define an action for when the mouse releases the copy  
copy.onMouseUp = dropGift;  
}

// the drop action for a gift that has been dragged  
// assigned in copyGiftForDrag  
function dropGift(){  
// stop dragging copy  
stopDrag();  
// if the mouse is within the area of the dropareaCheck\_mc clip  
// dropareaAttach\_mc shouldn’t be used since its size can change  
// based on what clips are attached to it (which can make it bigger)  
if (dropareaCheck\_mc.hitTest(\_root.\_xmouse, \_root.\_ymouse)){  
// attach the clip to the dropareaAttach\_mc, using a transformed  
// position to make sure it attaches in the same visual spot  
var position = transformPosition(this, this.\_parent, dropareaAttach\_mc);  
dropareaAttach\_mc.attachMovie(this.\_name, “gift”+dropareaAttach\_mc.depth, dropareaAttach\_mc.depth, position);  
dropareaAttach\_mc.depth++; // increase depth for next drag and drop  
}  
this.removeMovieClip();  
}

// transform a position (\_x and \_y) from one movie clip  
// to another marking a similar location on the screen  
// used in dropGift  
function transformPosition(position, from\_mc, to\_mc){  
// use localToGlobal and globalToLocal to transform the  
// position/point from one timeline to another  
var point = {x:position.\_x, y:position.\_y};  
from\_mc.localToGlobal(point);  
to\_mc.globalToLocal(point);  
position = {\_x:point.x, \_y:point.y};  
return position;  
}

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

// set a variable to keep drack of depths for  
// dropareaAttach\_mc which is where gifts are attached  
dropareaAttach\_mc.depth = 0;

// assign onPress functions for gifts in menu\_mc clip  
// the instance names of these clips need to be the same  
// as their linkage ID’s so that copies can be created  
// for the drag and drop operations  
menu\_mc.giftgreen.onPress = copyGiftForDrag;  
menu\_mc.giftblue.onPress = copyGiftForDrag;  
menu\_mc.giftred.onPress = copyGiftForDrag;
