5 Replies Latest reply on Nov 20, 2011 9:08 AM by LukeElChul

    HitTest Wont Work

    LukeElChul Level 1

      well ive made this code and ive checked it all works but the only thing that dosent work is the hitest can you suggest anything??????? if(this.hitTest(_root.player)){ trace("HIT!") _root.NormalCellArray.push(this); this.onPress=function(){         startDrag("");         }         this.onRelease=function(){         stopDrag(); } } Its on the first frame inside one of my movieClips.

        • 1. Re: HitTest Wont Work
          LukeElChul Level 1

          sorry the code didnt post right

           

          if(this.hitTest(_root.player)){

          trace("HIT!")

          _root.NormalCellArray.push(this);

          this.onPress=function(){ 

                 startDrag("");  

                }    

              this.onRelease=function(){

                  stopDrag();

          }

          }

          • 2. Re: HitTest Wont Work
            Ned Murphy Adobe Community Professional & MVP

            What do you mean when you say it all works?  What part of it is working?  The whole bit of code is conditional upon the hitTest working, so if the hitTest isn't working I don't see how the rest of it is working.  What is the intention of the code?

            1 person found this helpful
            • 3. Re: HitTest Wont Work
              LukeElChul Level 1

              well what i done was tuck the hit test out the code and ran it, the drag and drop worked.

               

              i removed this:

               

              if(this.hitTest(_root.player)){

               

               

              the intention is for the player to touch the movieClip and you will be able to drag and drop the movie clip/s.

              • 4. Re: HitTest Wont Work
                Ned Murphy Adobe Community Professional & MVP

                If you remove the hit test then it will drag/drop.  Otherwise, the code that tells the object to be dragged and dropped will not execute unless the hitTest tests true as soon as the file starts.

                 

                If this is like any other drag/drop situation, you probably want that hittest written inside the onRelease function, so that it checks if the object was dropped on the target....

                 

                this.onPress=function(){ 

                       startDrag("");  

                }    

                 

                this.onRelease=function(){

                        stopDrag();

                        if(this.hitTest(_root.player)){

                            trace("HIT!")

                            _root.NormalCellArray.push(this);

                        }

                }

                • 5. Re: HitTest Wont Work
                  LukeElChul Level 1

                  sorry it tuck me so long to reply ive figered it out i used.

                   

                   

                  function Turn(){

                  _root.NormalCellArray.push(this);

                   

                  import mx.transitions.Tween;

                  import mx.transitions.easing.*;

                   

                  this.onRelease = function(){

                  this.onMouseUp = function(){

                  var t1:Tween = new Tween(this, "_x", None.easeNone, this._x, _root._xmouse, 10, true);

                  var t2:Tween = new Tween(this, "_y", None.easeNone, this._y, _root._ymouse, 10, true);

                  delete this.onMouseUp;

                    }

                  }

                  }

                   

                  also used this on scene1 in a movieclip.

                   

                  onClipEvent(enterFrame){

                  if(this.hitTest(_root.player)){

                         if(size>=_root.playersize){

                  _root.player.gotoAndStop(2);//dies

                      }else if(size<=_root.playersize){

                       Turn()

                       //does Something

                      }

                      }

                  }

                   

                  thanks (:

                  1 person found this helpful