3 Replies Latest reply on Nov 7, 2012 6:36 AM by kglad

    Drag and drop target inside a movie clip

    enciel17

      Hi!

       

      I need help figuring this one out. I got a code from searching thru the net and was able to make it work. Although the problem I am facing now is the sample code works when everything is declared in the root and the droptarget won't work when it's inside a movie clip. But i need it to work inside a movie clip. I hope you can help me. I am still learning AS2.

       

      So basically this is what I am working with. I am able to drag items inside the target area and when it is out of target area it goes back to its original position. Everything works when in root but can't make it work when its inside a movie clip.

       

      I have a movie clip with a named instance called decor and inside it is a draggable movie clip with named with an instance circle_mc and of course another movie clip with an instance targetCircle

       

      I have placed an actionscript on the circle_mc movie clip which is:

       

      on (press){

                this.swapDepths(998);

                startDrag("");

      }

      on (release)

      { stopDrag ();

       

       

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

       

      this.onTarget=true;

      _root.targetCircle.gotoAndStop(2);               //i tried changing this line to decor.targetCircle.gotoAndStop(2); and still does not work

      }else{

      this.onTarget=false;

      root.targetCircle.gotoAndStop(1)                  //i tried changing this line to decor.targetCircle.gotoAndStop(1); and still does not work

      }

       

      }

       

       

      on(releaseOutside) {

      stopDrag();}

       

      and then added this code on the frame:

       

      circle_mc.myHomeX=circle_mc._x;

      circle_mc.myHomeY=circle_mc._y;

       

       

      circle_mc.onMouseDown=function(){

      //this variable tells us if the mouse is up or down

      mousePressed=true;

      }

      circle_mc.onMouseUp=function(){

      mousePressed=false;

      }

      circle_mc.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)

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

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

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

       

       

      }

      }

       

      Message was edited by: enciel17