# Drag and Drop multiple boxes and snap to multiple locations then reveal button

**URL:** <https://forum.kirupa.com/t/drag-and-drop-multiple-boxes-and-snap-to-multiple-locations-then-reveal-button/321873>\
**Category:** flash\
**Created:** [May 4, 2011, 4:48am UTC](https://forum.kirupa.com/t/drag-and-drop-multiple-boxes-and-snap-to-multiple-locations-then-reveal-button/321873 "2011-05-04T04:48:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lukeh](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@lukeh](https://forum.kirupa.com/u/lukeh)\
**Post date:** [May 4, 2011, 4:48am UTC](https://forum.kirupa.com/t/drag-and-drop-multiple-boxes-and-snap-to-multiple-locations-then-reveal-button/321873/1 "2011-05-04T04:48:06Z")

</div>

Hi I’m Trying to develop a small game where the user chooses from a range of boxes of the left of screen and can drag 3 of them separatley to 3 holding boxes on ther right. each box can be dragged to any location and the order is not important. Once the 3 holding boxes are all full I want a new button to appear. I have some draggable boxes but for some reason they wont snap to the locations. Below is a a link to the file and a list of the instance names of the movie clips plus my actionscript. Any help would be really appreciated. Cheers

**LINK**

[http://www.sainters.net/flash\_preview/flash\_test/flash test\_v6.fla.zip](http://www.sainters.net/flash_preview/flash_test/flash%20test_v6.fla.zip)

box 1 = “circle\_mc”

box 2 = “circle\_mc2”

top grey box = “targetCircle1”

bottom grey box = “targetCircle2”

**ACTIONSCRIPT**

function dragSetup(clip, targ) {  
clip.onPress = function() {  
startDrag(this);  
this.beingDragged=true;

};

clip.onRelease = clip.onReleaseOutside=function () {  
stopDrag();  
this.beingDragged=false;  
**if (this.\_droptarget.isTarget) {  
this.\_droptarget.isTarget = false;**  
\_root.targ.gotoAndStop(2);  
} else {  
this.onTarget = false;  
\_root.targ.gotoAndStop(1);

}  
};  
//the variables below will store the clips starting position  
clip.myHomeX = clip.\_x;  
clip.myHomeY = clip.\_y;

//the variables below will store the clips end position  
clip.myFinalX = targ.\_x;  
clip.myFinalY = targ.\_y;

clip.onEnterFrame = function() {  
//all these actions basically just say “if the mouse is up (in other words - the clip is not being dragged)  
// then move the MC back to its original starting point (with a smooth motion)”  
if (!this.beingDragged && !this.onTarget) {  
this.\_x -= (this.\_x-this.myHomeX)/5;  
this.\_y -= (this.\_y-this.myHomeY)/5;  
//if the circle is dropped on any part of the target it slides to the center of the target  
} else if (!this.beingDragged && this.onTarget) {  
this.\_x -= (this.\_x-this.myFinalX)/5;  
this.\_y -= (this.\_y-this.myFinalY)/5;  
**targetCircle1.isTarget == true;  
targetCircle2.isTarget == true;**

}  
}  
}

\*\*dragSetup(circle\_mc); // left off second argument purposefully

dragSetup(circle\_mc2);\*\*
