3 Replies Latest reply on May 30, 2011 6:13 PM by luke_hon

    Issue with drag and drop

    luke_hon

      Hi I'm developing a simple drag and drop game. I posted on here last week and have made alot of progress. the idea is when "box 1" is dragged over to the right and dropped over the "1." it snaps, if it misses it will return it's original location. This all works fine but there is some dodgy behaviour. For instance if you "drop box 1" on to the "1."  then if you pick it up again and drag it as far as you can offscreen it returns to it's original location. but then when you attempt to drag it again it gets stuck and wont follow the mouse pointer correctly. Any help would be greatly appreciated. Below is a link and my aciton script. Cheers

       

       

      http://www.sainters.net/flash_preview/flash_test/

       

       

       

       

      targetCircle1.isTarget = true;  // these need to be done outside the clip code
      targetCircle2.isTarget = true;
      targetCircle3.isTarget = true;
      function dragSetup(clip) {
         
         

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

      clip.onPress = function() {
        startDrag(this);
      };
      clip.onRelease = clip.onReleaseOutside=function () {
        stopDrag();
        this.onTarget = false;
       
           // default to assuming it's a failed attempt
        clip.myFinalX = clip.myHomeX;
        clip.myFinalY = clip.myHomeY;
       
        var thisTarget = eval(this._droptarget);
        if (thisTarget.isTarget) {
        //delete clip.onPress; // disable dragging for this clip
        // thisTarget.isTarget = false; // disable the target
         this.onTarget = true;
         _root.thisTarget.gotoAndplay(2);
            //the variables below will store the clips end position
               clip.myFinalX = thisTarget._x;
               clip.myFinalY = thisTarget._y;
               
             
        // gotoAndPlay("join");
       
       
               
               
               
             
        }
       
       
       
       
        // relocate the clip depending on myFinalX/Y values
        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)"
         this._x -= (this._x-this.myFinalX)/5;
         this._y -= (this._y-this.myFinalY)/5;

       

         //check for near completion and end it - remove enterframe activity
         if(this._x-this.myFinalX < 1 && this._y-this.myFinalY < 1){
          this._x = this.myFinalX;
          this._y = this.myFinalY;
         
          delete clip.onEnterFrame;
         
          //gotoAndPlay("join");
         }
        }
      }
      }

       

      dragSetup(circle_mc);