7 Replies Latest reply on Jan 21, 2016 11:28 AM by kglad

    How to move an object to specific area

    khateebkhan Level 1

      I want to move two objects in two areas but one area is specified for one object but not for the other. When that object is moved to the second area not specified for that then that object should come back to its original position.

        • 1. Re: How to move an object to specific area
          kglad Adobe Community Professional & MVP

          make both objects movieclips and assign a property to each that indicates its target.

           

          use a hitTestObject to determine if each is dropped on its target.

          • 2. Re: How to move an object to specific area
            khateebkhan Level 1

            how to assign property that indicate target to movieclip in actionscript 2.0 and 3.0

            • 3. Re: How to move an object to specific area
              kglad Adobe Community Professional & MVP

              it's the same in as2 and as3:

               

              yourmovieclip.target=whatever;

              • 4. Re: How to move an object to specific area
                khateebkhan Level 1

                I am trying this code and it is working perfectly:

                 

                chk.onPress=function(){

                  startDrag(this);

                }

                chk.onRelease=function(){

                  stopDrag();

                  checkTarget(this);

                }

                chk.onReleaseOutside=function(){

                  stopDrag();

                  checkTarget(this);

                }

                function checkTarget(drag){

                  if(eval(chk._droptarget)==squ4)

                  {

                  chk._x=770;

                  chk._y=330;

                  }else{

                  chk._x=455;

                  chk._y=550;

                    }

                }javascript:;

                 

                But i have to add another object as below but as soon as i do this, the above stops working.

                 

                bird.onPress=function(){

                  startDrag(this);

                }

                bird.onRelease=function(){

                  stopDrag();

                  checkTarget(this);

                }

                bird.onReleaseOutside=function(){

                  stopDrag();

                  checkTarget(this);

                }

                function checkTarget(drag){

                  if(eval(bird._droptarget)==squ4)

                  {

                  bird._x=770;

                  bird._y=330;

                  }else{

                  bird._x=870;

                  bird._y=555;

                    }

                }

                Picture1.png

                • 5. Re: How to move an object to specific area
                  kglad Adobe Community Professional & MVP

                  use:

                   

                  var birdA:Array=[bird1,bird2,bird3,bird4];

                  for(var i:Number=0;i<birdA.length;i++){

                  birdA[[i].target=squ4;

                  birdA[i].onPress=startDragF;

                  birdA[i].onRelease=birdA[i].onReleaseOutside=stopDragF;

                  birdA[i].startX=birdA[i]._x;

                  birdA[i].startY=birdA[i]._y;

                  }

                  function startDragF():Void{

                  this.startDrag();

                  }

                  function stopDragF():Void{

                  this.stopDrag();

                  if(eval(this._dropTarget)==this.target){

                  this._x = this.target._x;

                  this._y = this.target._y;

                  } else {

                  this._x = this.startX;

                  this._y = this.startY;

                  }

                  }

                  • 6. Re: How to move an object to specific area
                    khateebkhan Level 1

                    how to code the rest?

                    I mean chk was for chicken which we have to move squ4. Now birds also have to move to squ4.

                    but bears and pencils have to move to squr4.

                     

                    when one coding is done, its fine, but when other is done, first just vanishes.

                    • 7. Re: How to move an object to specific area
                      kglad Adobe Community Professional & MVP

                      use:

                       

                      var birdA:Array=[bird1,bird2,bird3,bird4];

                      var chickA:Array=[chk1,chk2,chk3,chk4];

                      var bearA:Array=[bear1,bear2,bear3];

                      var pencilA:Array=[pencil1,pencil2,pencil3];

                      ////

                      handlerF(birdA.squ4);

                      handlerF(chickA.squ4);

                      handlerF(bearA.squr4);

                      handlerF(pencilA.squr4);

                       

                      function handlerF(a:Array,target:MovieClip):Void{

                      for(var i:Number=0;i<a.length;i++){

                      a[[i].target=target;

                      a[i].onPress=startDragF;

                      a[i].onRelease=a.onReleaseOutside=stopDragF;

                      a[i].startX=a[i]._x;

                      a[i].startY=a[i]._y;

                      }

                      }

                       

                       

                       

                      function startDragF():Void{

                      this.startDrag();

                      }

                      function stopDragF():Void{

                      this.stopDrag();

                      if(eval(this._dropTarget)==this.target){

                      this._x = this.target._x;

                      this._y = this.target._y;

                      } else {

                      this._x = this.startX;

                      this._y = this.startY;

                      }

                      }