3 Replies Latest reply on Nov 30, 2009 2:51 PM by kglad

    Drag and Drop bug

    Sid.Flint

      Hello!

      I am working on a simple "Drag and Drop" deal and I have encountered an interesting bug that I can't seem to track down.

      When testing the movie, the FIRST TIME you click and drag any of the objects (black circles in this case) to their target (the big rectangle), all is well.

      However upon dragging them OUT of the target area, the object appears to "fight back" against being dragged.

       

      I am fairly new to Actionscript and can't seem to find the answer for this one elsewhere.  Any help would be greatly appreciated!

       

      I'm going to apologize in advance for the messy script. 

      // Drag Properties

      /*1*/

      circle_mc.onPress=function(){

           startDrag(this);

      };

      circle_mc.onRelease = circle_mc.onReleaseOutside=function(){

           stopDrag();

           if (this._droptarget =="/targetBox"){

                this.onTarget = true;

                _root.circle_mc.gotoAndStop(2);

                _root.targetBox.gotoAndPlay(2);

           }else{

                this.onTarget = false;

                _root.circle_mc.gotoAndStop(1);

                _root.targetBox.gotoAndStop(1);

           }

      };

       

      /*2*/

      circle2_mc.onPress=function(){

           startDrag(this);

      };

      circle2_mc.onRelease = circle2_mc.onReleaseOutside=function(){

           stopDrag();

           if (this._droptarget =="/targetBox"){

                this.onTarget = true;

                _root.circle2_mc.gotoAndStop(2);

                _root.targetBox.gotoAndPlay(2);

           }else{

                this.onTarget = false;

                _root.circle2_mc.gotoAndStop(1);

                _root.targetBox.gotoAndStop(1);

           }

      };

       

      /*3*/

      circle3_mc.onPress=function(){

           startDrag(this);

      };

      circle3_mc.onRelease = circle3_mc.onReleaseOutside=function(){

           stopDrag();

           if (this._droptarget =="/targetBox"){

                this.onTarget = true;

                _root.circle3_mc.gotoAndStop(2);

                _root.targetBox.gotoAndPlay(2);

           }else{

                this.onTarget = false;

                _root.circle3_mc.gotoAndStop(1);

                _root.targetBox.gotoAndStop(1);

           }

      };

       

       

       

      // Starting Position variables

      circle_mc.myHomeX=circle_mc._x;

      circle_mc.myHomeY=circle_mc._y;

       

      circle2_mc.myHomeX=circle2_mc._x;

      circle2_mc.myHomeY=circle2_mc._y;

       

      circle3_mc.myHomeX=circle3_mc._x;

      circle3_mc.myHomeY=circle3_mc._y;

       

      // Ending Position variables

      circle_mc.myFinalX = targetBox._x + 85;

      circle_mc.myFinalY = targetBox._y;

       

      circle2_mc.myFinalX = targetBox._x;

      circle2_mc.myFinalY = targetBox._y;

       

      circle3_mc.myFinalX = targetBox._x - 85;

      circle3_mc.myFinalY = targetBox._y;

       

       

      // Mouse Up / Mouse Down

      mousePressed = true;

      circle_mc.onMouseUp = function(){

           mousePressed = false;

      };

      circle2_mc.onMouseUp = function(){

           mousePressed = false;

      };

      circle3_mc.onMouseUp = function(){

           mousePressed = false;

      };

       

      circle_mc.onEnterFrame = function(){

           if(mousePressed == false&&this.onTarget == false){

                this._x-=(this._x-this.myHomeX)/5;

                this._y-=(this._y-this.myHomeY)/5;

           }

      else if(mousePressed == false&&this.onTarget == true){

           this._x-=(this._x-this.myFinalX)/5;

           this._y-=(this._y-this.myFinalY)/5;

           }

      }

       

       

      circle2_mc.onEnterFrame = function(){

           if(mousePressed == false&&this.onTarget == false){

                this._x-=(this._x-this.myHomeX)/5;

                this._y-=(this._y-this.myHomeY)/5;

           }

      else if(mousePressed == false&&this.onTarget == true){

           this._x-=(this._x-this.myFinalX)/5;

           this._y-=(this._y-this.myFinalY)/5;

           }

      }

       

      circle3_mc.onEnterFrame = function(){

           if(mousePressed == false&&this.onTarget == false){

                this._x-=(this._x-this.myHomeX)/5;

                this._y-=(this._y-this.myHomeY)/5;

           }

      else if(mousePressed == false&&this.onTarget == true){

           this._x-=(this._x-this.myFinalX)/5;

           this._y-=(this._y-this.myFinalY)/5;

           }

      }