# Drag and Drop MC

**URL:** https://forum.kirupa.com/t/drag-and-drop-mc/327824
**Category:** flash
**Created:** [March 30, 2012, 1:04pm UTC](https://forum.kirupa.com/t/drag-and-drop-mc/327824 "2012-03-30T13:04:08Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![MAGG0T](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@MAGG0T](https://forum.kirupa.com/u/MAGG0T)
#### Post date: [March 30, 2012, 1:04pm UTC](https://forum.kirupa.com/t/drag-and-drop-mc/327824/1 "2012-03-30T13:04:08Z")

</div>

[COLOR=#000000][FONT=verdana]I have a drag and drop which works fine on the 1st scene frame 1 within its own movieclip but when i try to add it to another movieclip “contentbg” it stops working i also correct the paths to the right paths but still doesnt work heres the actionscript of the working MC:[/FONT][/COLOR]

[COLOR=#000000][FONT=verdana]master\_mc.circle\_mc.onPress = function() {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]startDrag(this);[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]};[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]master\_mc.circle\_mc.onRelease = master\_mc.circle\_mc.onReleaseOutside=function () {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]stopDrag();[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]trace(this.\_droptarget);[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]if (this.\_droptarget == “/master\_mc/targetCircle”) {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]this.onTarget = true;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]\_root.master\_mc.targetCircle.gotoAndStop(2);[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]} else {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]this.onTarget = false;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]\_root.targetCircle.gotoAndStop(1);[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]}[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]};[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]//the variables below will store the clips starting position[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]master\_mc.circle\_mc.myHomeX=master\_mc.circle\_mc.\_x ;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]master\_mc.circle\_mc.myHomeY=master\_mc.circle\_mc.\_y ;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]//the variables below will store the clips end position[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]master\_mc.circle\_mc.myFinalX = 45.6;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]master\_mc.circle\_mc.myFinalY = 37.0;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]master\_mc.circle\_mc.onMouseDown = function() {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]//this variable tells us if the mouse is up or down[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]mousePressed = true;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]};[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]master\_mc.circle\_mc.onMouseUp = function() {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]mousePressed = false;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]};[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]master\_mc.circle\_mc.onEnterFrame = function() {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]//all these actions basically just say “if the mouse is up (in other words - the clip is not being dragged)[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]// then move the MC back to its original starting point (with a smooth motion)”[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]if (mousePressed == false && this.onTarget == false) {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]this.\_x -= (this.\_x-this.myHomeX)/5;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]this.\_y -= (this.\_y-this.myHomeY)/5;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]//if the circle is dropped on any part of the target it slides to the center of the target[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]} else if (mousePressed == false && this.onTarget == true) {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]this.\_x -= (this.\_x-this.myFinalX)/5;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]this.\_y -= (this.\_y-this.myFinalY)/5;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]}[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]};[/FONT][/COLOR]

[COLOR=#000000][FONT=verdana]//start dragable image 2 and target [/FONT][/COLOR]

[COLOR=#000000][FONT=verdana]master\_mc.circle\_mc2.onPress = function() {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]startDrag(this);[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]};[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]master\_mc.circle\_mc2.onRelease = master\_mc.circle\_mc2.onReleaseOutside=function () {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]stopDrag();[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]if (this.\_droptarget == “/master\_mc/targetCircle2”) {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]this.onTarget = true;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]\_root.master\_mc.targetCircle2.gotoAndStop(2);[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]} else {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]this.onTarget = false;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]\_root.targetCircle2.gotoAndStop(1);[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]}[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]};[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]//the variables below will store the clips starting position[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]master\_mc.circle\_mc2.myHomeX=master\_mc.circle\_mc2. \_x;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]master\_mc.circle\_mc2.myHomeY=master\_mc.circle\_mc2. \_y;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]//the variables below will store the clips end position[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]master\_mc.circle\_mc2.myFinalX = 118.5;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]master\_mc.circle\_mc2.myFinalY = 37.0;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]master\_mc.circle\_mc2.onMouseDown = function() {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]//this variable tells us if the mouse is up or down[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]mousePressed = true;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]};[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]master\_mc.circle\_mc2.onMouseUp = function() {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]mousePressed = false;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]};[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]master\_mc.circle\_mc2.onEnterFrame = function() {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]//all these actions basically just say “if the mouse is up (in other words - the clip is not being dragged)[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]// then move the MC back to its original starting point (with a smooth motion)”[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]if (mousePressed == false && this.onTarget == false) {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]this.\_x -= (this.\_x-this.myHomeX)/5;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]this.\_y -= (this.\_y-this.myHomeY)/5;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]//if the circle is dropped on any part of the target it slides to the center of the target[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]} else if (mousePressed == false && this.onTarget == true) {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]this.\_x -= (this.\_x-this.myFinalX)/5;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]this.\_y -= (this.\_y-this.myFinalY)/5;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]}[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]};[/FONT][/COLOR]

[COLOR=#000000][FONT=verdana]Here is the script with up to date paths that doesn’t work[/FONT][/COLOR]

[COLOR=#000000][FONT=verdana]contentbg.master\_mc.circle\_mc.onPress = function() {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]startDrag(this);[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]};[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]contentbg.master\_mc.circle\_mc.onRelease = contentbg.master\_mc.circle\_mc.onReleaseOutside=fun ction () {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]stopDrag();[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]trace(this.\_droptarget);[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]if (this.\_droptarget == “/contentbg/master\_mc/targetCircle”) {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]this.onTarget = true;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]\_root.contentbg.master\_mc.targetCircle.gotoAndStop (2);[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]} else {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]this.onTarget = false;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]\_root.contentbg.targetCircle.gotoAndStop(1);[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]}[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]};[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]//the variables below will store the clips starting position[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]contentbg.master\_mc.circle\_mc.myHomeX=contentbg.ma ster\_mc.circle\_mc.\_x;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]contentbg.master\_mc.circle\_mc.myHomeY=contentbg.ma ster\_mc.circle\_mc.\_y;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]//the variables below will store the clips end position[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]contentbg.master\_mc.circle\_mc.myFinalX = 45.6;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]contentbg.master\_mc.circle\_mc.myFinalY = 37.0;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]contentbg.master\_mc.circle\_mc.onMouseDown = function() {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]//this variable tells us if the mouse is up or down[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]mousePressed = true;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]};[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]contentbg.master\_mc.circle\_mc.onMouseUp = function() {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]mousePressed = false;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]};[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]contentbg.master\_mc.circle\_mc.onEnterFrame = function() {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]//all these actions basically just say “if the mouse is up (in other words - the clip is not being dragged)[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]// then move the MC back to its original starting point (with a smooth motion)”[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]if (mousePressed == false && this.onTarget == false) {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]this.\_x -= (this.\_x-this.myHomeX)/5;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]this.\_y -= (this.\_y-this.myHomeY)/5;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]//if the circle is dropped on any part of the target it slides to the center of the target[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]} else if (mousePressed == false && this.onTarget == true) {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]this.\_x -= (this.\_x-this.myFinalX)/5;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]this.\_y -= (this.\_y-this.myFinalY)/5;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]}[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]};[/FONT][/COLOR]

[COLOR=#000000][FONT=verdana]//start dragable image 2 and target [/FONT][/COLOR]

[COLOR=#000000][FONT=verdana]contentbg.master\_mc.circle\_mc2.onPress = function() {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]startDrag(this);[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]};[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]contentbg.master\_mc.circle\_mc2.onRelease = contentbg.master\_mc.circle\_mc2.onReleaseOutside=fu nction () {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]stopDrag();[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]if (this.\_droptarget == “/contentbg/master\_mc/targetCircle2”) {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]this.onTarget = true;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]\_root.contentbg.master\_mc.targetCircle2.gotoAndSto p(2);[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]} else {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]this.onTarget = false;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]\_root.contentbg.targetCircle2.gotoAndStop(1);[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]}[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]};[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]//the variables below will store the clips starting position[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]contentbg.master\_mc.circle\_mc2.myHomeX=master\_mc.c ircle\_mc2.\_x;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]contentbg.master\_mc.circle\_mc2.myHomeY=master\_mc.c ircle\_mc2.\_y;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]//the variables below will store the clips end position[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]contentbg.master\_mc.circle\_mc2.myFinalX = 118.5;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]contentbg.master\_mc.circle\_mc2.myFinalY = 37.0;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]contentbg.master\_mc.circle\_mc2.onMouseDown = function() {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]//this variable tells us if the mouse is up or down[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]mousePressed = true;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]};[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]contentbg.master\_mc.circle\_mc2.onMouseUp = function() {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]mousePressed = false;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]};[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]contentbg.master\_mc.circle\_mc2.onEnterFrame = function() {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]//all these actions basically just say “if the mouse is up (in other words - the clip is not being dragged)[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]// then move the MC back to its original starting point (with a smooth motion)”[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]if (mousePressed == false && this.onTarget == false) {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]this.\_x -= (this.\_x-this.myHomeX)/5;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]this.\_y -= (this.\_y-this.myHomeY)/5;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]//if the circle is dropped on any part of the target it slides to the center of the target[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]} else if (mousePressed == false && this.onTarget == true) {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]this.\_x -= (this.\_x-this.myFinalX)/5;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]this.\_y -= (this.\_y-this.myFinalY)/5;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]}[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]};[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]stop();[/FONT][/COLOR]
