5 Replies Latest reply on Mar 8, 2010 5:19 PM by kglad

    hitTest question

    TheBrody Level 1

      How can I make it so if an object with the instance name of item1, item2, item3, etc.. make it trace "Hey".

       

      I'm just trying to make it so it does every instance name with item and a number after.

        • 1. Re: hitTest question
          kglad Adobe Community Professional & MVP

          that doesn't make sense.

           

          you're trying to do hitTests between item1,item2 etc and some other movieclip?  or, you're trying to do hitTests between each pair of item1, item2 etc?  or, something else?

          • 2. Re: hitTest question
            TheBrody Level 1

            I have a button, each time you press the button it makes an object with the instance name item 1 then you press it again, it makes one called item 2, etc..

             

            So I want it so if those objects with the name item(number) are touching something named "box". Then it will trace("hey");

            • 3. Re: hitTest question
              kglad Adobe Community Professional & MVP

              when do you want to execute these hittest?   once immediately after an item is created?  repeatedly after it'created?  if it's tested more than once, will the hittests for that item ever stop?

              • 4. Re: hitTest question
                TheBrody Level 1

                I made it so I can drag the object... So I guess after its created, and nonstop.

                • 5. Re: hitTest question
                  kglad Adobe Community Professional & MVP

                  then you don't want to check non-stop, only while dragging.

                   

                  so, you'd use something like:

                   

                  var item:MovieClip = whatever you do to create an item mc

                  item.onPress=function(){

                  this.startDrag();

                  this.onEnterFrame=checkHit;

                  }

                  item.onRelease=item.onReleaseOutside=function(){

                  this.stopDrag();

                  delete this.onEnterFrame;

                  }

                   

                   

                  .

                  .

                  .

                   

                  function checkHit(){

                  if(this.hitTest(box)){

                  trace("HIT");

                  // you may want to execute:

                  //delete this.onEnterFrame

                  }

                  }