2 Replies Latest reply on Jan 8, 2010 6:53 AM by RossRitchey

    Movieclip in buttonMode - draggable to different movieclip target

    xxxheeroxxx Level 1

      Good day,

       

           I'm doing a project that makes a movieclip draggable in different droptarget movieclip. When it is dragged in the 1st target an animation is triggered and so as the rest of the droptargets.

       

      Here's my initial code that does'nt work:

       

      btn1.buttonMode = true;


      b1OrigX = btn1._x;
      b1OrigY = btn1._y;

       

      //btn1
      btn1.onPress = function(){
          startDrag(this);
      }
      //droptarget = box1
      btn1.onRelease = function(){
          stopDrag();
             //droptarge1t = box1
          if (eval(this._droptarget) == box1) {
              trace("test1");
              droptarget1_btn1.gotoAndPlay("play");
             this._x = b1OrigX;
              this._y = b1OrigY;
          }else{
              this._x = b1OrigX;
             this._y = b1OrigY;
          }

       

           the 2nd droptarget will not be performed anymore.


          //droptarget2 = box2
          if (eval(this._droptarget) == box2) {
              trace("test2");
              droptarget2_btn1.gotoAndPlay("play");
          }else{
              this._x = b1OrigX;
              this._y = b1OrigY;
          }
         
      }
      //end of btn1

        • 1. Re: Movieclip in buttonMode - draggable to different movieclip target
          RossRitchey Level 4

          It appears as though the second one will never work, because the first if statement resets the position of the button if it isn't dropped on box1.

           

          To fix, the if statement should be singular, and the reposition separate:

           

          btn1.buttonMode = true;
          
          b1OrigX = btn1._x;
          b1OrigY = btn1._y;
          
          //btn1
          btn1.onPress = function(){
              startDrag(this);
          }
          
          btn1.onRelease = function(){
              stopDrag();
                 //droptarge1t = box1
              if (eval(this._droptarget) == box1) {
                  trace("test1");
                  droptarget1_btn1.gotoAndPlay("play");
               }else if (eval(this._droptarget) == box2) {
                  trace("test2");
                  droptarget2_btn1.gotoAndPlay("play");
              }
              this._x = b1OrigX;
              this._y = b1OrigY;    
          }
          //end of btn1
          
          

          • 2. Re: Movieclip in buttonMode - draggable to different movieclip target
            xxxheeroxxx Level 1

            Thanks for the reply man.

             

            I guess I did'nt explain it very well.

             

            Here's another code I came out.

             

             

            btn1.onRelease = function(){
                stopDrag();

             

                //droptarget1 = box1
                if (eval(this._droptarget) == box1) {
                    droptarget1_btn1.gotoAndPlay("play");
                }
                if (eval(this._droptarget) == box2) {
                    droptarget2_btn1.gotoAndPlay("play");
                }
                if (eval(this._droptarget) == box3){
                    droptarget3_btn1.gotoAndPlay("play");
                }
            }

             

            I want to animate the drag and drop of one button to different droptargets simultaneously.

             

            If I drag and drop btn1 to box1 the inside animation of this droptarget1_btn1 movieclip will play so as the other movieclip under box2 and box3.