7 Replies Latest reply on Aug 18, 2010 4:26 AM by Ned Murphy

    hitTest question???

    dn0myar06 Level 1

      is it possible to perform a htTest between mc's within another mc, coz mine's not working...

        • 1. Re: hitTest question???
          Ned Murphy Adobe Community Professional & MVP

          Show the code you are using and describe the setup

          • 2. Re: hitTest question???
            dn0myar06 Level 1

            i'm creating a game....the object is to catch falling mangoes, so i put a small object object in the mango mc, and another object to the basket, so when they hit each other, score will be added and removeMovieClip() will be performed...

             

            Here's my code:

             

            onClipEvent (enterFrame) {
                if (_root.inMango_mc, hitTest(_root.inBasket_mc)) {
                    gotoAndPlay(2);          //frame 2 contains the removeMovieClip()
                    _root.score +=2
                }
            }

            • 3. Re: hitTest question???
              Ned Murphy Adobe Community Professional & MVP

              Your description is a little unclear.  If you have objects on the root timeline with the names you say, then the only problem I can currently determine is you have a comma where you should have a period (and no space)...

               

              if (_root.inMango_mc.hitTest(_root.inBasket_mc)) {

                                  |

                                 here

              • 4. Re: hitTest question???
                dn0myar06 Level 1

                i actually got the code from here: http://www.kirupa.com/developer/actionscript/hittest.htm


                i've used it before and it works fine for me....

                 

                my problem is, this time the hitTest doesn't perform....is it probably because they are inside a different MC's??

                 

                The first object that I'm trying to have a HitTest is inside Mango mc

                And the second object is inside the Character mc that has another mc that figures wether walk left or right.

                 

                is it possible to perform hitTest between them??

                • 5. Re: hitTest question???
                  Ned Murphy Adobe Community Professional & MVP

                  You can get them to register a hit if you target them, but the code you show will not do that if the objects are inside other objects.  You would need to use _root.object1.object2 (just an example) to point at an object (object2) that is inside another object (object1).

                  1 person found this helpful
                  • 6. Re: hitTest question???
                    dn0myar06 Level 1

                    thanks but it's still not working...

                     

                    should they be on the same timeline??

                    • 7. Re: hitTest question???
                      Ned Murphy Adobe Community Professional & MVP

                      It appears you followed what kGlad offered, which is the same as what I offered... you need to target the objects based on whatever timeline you are operating from, except in your case you were targeting them via using a _root timeline reference.