# Drag and Drop issue

**URL:** <https://forum.kirupa.com/t/drag-and-drop-issue/328542>\
**Category:** flash\
**Created:** [May 24, 2012, 3:27pm UTC](https://forum.kirupa.com/t/drag-and-drop-issue/328542 "2012-05-24T15:27:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jason\_Romans](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@Jason\_Romans](https://forum.kirupa.com/u/Jason_Romans)\
**Post date:** [May 24, 2012, 3:27pm UTC](https://forum.kirupa.com/t/drag-and-drop-issue/328542/1 "2012-05-24T15:27:06Z")

</div>

Hi,

I am updating these files, and I ran across a problem with the drag and drops allowing for the drag objects to be able to drop on the same target, I have tried a few different things to fix it, but I seem to be missing something…

Files:  
[http://www.jkromans.com/Work/dd.swf](http://www.jkromans.com/Work/dd.swf)  
[http://www.jkromans.com/Work/dd.fla](http://www.jkromans.com/Work/dd.fla)

DD Code:  
var maxDepth:Number = 200;  
init = function(){  
for(i=1; i\<=numQuestions; i++){  
//occupied\* = false;  
//trace("these are "+occupied\*);  
drag\_mc = this[“drag”+i];  
target\_mc = this[“drop”+i];  
trace("target\_mc initial values = "+target\_mc);  
drag\_mc.num = i;  
drag\_mc.whereDropped = 0;  
drag\_mc.onPress = function(){  
this.swapDepths(maxDepth+i);  
this.startDrag();  
this.initX = this.\_x;  
///target\_mc = undefined;  
//checkTarget(target\_mc);

```
    }
    drag_mc.onRelease = function(){
        this.swapDepths(maxDepth);
        this.stopDrag();
        var dt:String = this._droptarget
        var dropNum = Number(substring(dt,4,1));
        drag_mc.whereDropped = dropNum;
        //trace("dt = " + this.whereDropped)
        //trace("getProperty(this._droptarget, _x) = " + getProperty(this._droptarget, _x))
        trace("this is the target = "+target_mc);
        checkTargets();
        if (dt.indexOf("dz",dt.lastIndexOf(".")) &gt; 0)
        {
            target_mc = this._droptarget;
            trace("this is where this is being droped:"+this._droptarget+" also the target mc is equal to "+target_mc);
            if(target_mc != undefined){
                this._x = getProperty(this._droptarget, _x);
                this._y = getProperty(this._droptarget, _y);
                target_mc = this._droptarget;
                trace("target_mc value durring successful drop = "+target_mc);
            } else {
                
                trace("target_mc value durring unsuccessful drop = "+target_mc);
                trace("origX = "+this.origX+" and initX = "+this.initX);
                if(this.origX == this.initX){
                    trace("origX = "+this.origX+" and initX = "+this.initX);
                    this._x = this.origX;
                    this._y = this.origY;
                    target_mc = undefined;
                }
                //target_mc = undefined; test to see if the drag that occupied this item is what was moved...
                trace("target_mc value durring unsuccessful drop2 = "+target_mc);
            }
        }
        else
        {
            
            if(this.origX != this.initX){
                    trace("origX = "+this.origX+" and initX = "+this.initX);
                    this._x = this.origX;
                    this._y = this.origY;
                    target_mc = undefined;
            }
            
            trace("target_mc value durring outside drop = "+target_mc);
        }
    }    
}

```

}  
init();

Sorry for the jumbled code, I got to a &\*%^ it point. 😛

Thanks,  
-Jason
