8 Replies Latest reply on Nov 24, 2010 8:29 AM by Ned Murphy

    Hit Test Help

    unamus3d

      Is there away i can use hit test for mouse click.

       

      i have 2 MovieClips,  MC & mc.

      inside MC there is MC1

      inside mc there is mc1 & mc2

       

      if(_parent.MC.MC1, hitTest(_parent.mc.mc1))
         {
             _parent.mc.mc2.nextFrame();
         }

       

      Basicly if MC1 inside MC hits [mouse clicked] mc1 inside mc. Then mc2 inside mc goes to next frame.

       

      i understand my attempt is probably way wrong, i still dont grasp when to use _parent or _root.

        • 1. Re: Hit Test Help
          Ned Murphy Adobe Community Professional & MVP

          Whether or not you need to use _parent references depends on where the code is placed.  _parent references are normally used inside of objects to refer to the object/timeline that contains them.  So mc1 might use _parent.play if it wanted to tell mc to play, or if it wanted to reach back to the main timeline you could use _root.MC.play() if you wanted mc1 to tell MC to play (and MC is in the main timeline.

           

          If that code was on the main timeline along with MC and mc, then you do not want to use any parent references.

           

          Also, you have an error in your conditional, that comma should be a period with no space after it...

           

             MC.MC1.hitTest(...

          1 person found this helpful
          • 2. Re: Hit Test Help
            unamus3d Level 1

            if(MC._root.MC1.hitTest(mc._root.mc1))
               {
                   _root.mc.mc2.nextFrame();
               }

             

            is that any closer, it doesnt work but is that right at all :|

            • 3. Re: Hit Test Help
              Ned Murphy Adobe Community Professional & MVP

              No, you would not place either the _root or the _parent in the middle of a target for any good reason.  If you explain where your MC and mc objects are located, it will be easier to tell you what you need to use.  Also indicate where you are trying to place that code.

              1 person found this helpful
              • 4. Re: Hit Test Help
                unamus3d Level 1

                My apologies, i apreciate the help.

                MC and mc are 2 movie clips i have on the main timeline, they are on seperate layers.

                inside MC is 1 movieclip say MC1.

                inside mc there are 2 movie clips say mc1 and mc2.

                 

                MC is what im using for my mouse [rooted to cursor].

                 

                when MC1 [inside MC] hits[clicks] mc1 [inside mc]  ... mc2 [inside mc] goes to next frame.

                 

                I tryed to explain what im trying to do as simple as possible.

                • 5. Re: Hit Test Help
                  unamus3d Level 1

                  ive got it half working.

                  code on MC

                   

                   

                  if(_root.MC.hitTest(_parent.mc)

                  { trace("sucess");)

                   

                  it works if i try to test collision between these 2 but how do i do it with the movie clips inside the movie clips

                   

                  if(_root.MC.MC1.hitTest(_parent.mc.mc1)

                  {

                     trace("suces");

                  }

                   

                  thats all i can think of

                  • 6. Re: Hit Test Help
                    Ned Murphy Adobe Community Professional & MVP

                    You still haven't indicated where the code is (I think), but if MC and mc are on the main timeline, and you place the code on the main timeline, you could use...

                     

                     

                    if(MC.MC1.hitTest(mc.mc1)

                    {

                       trace("sucess");

                    }

                    • 7. Re: Hit Test Help
                      unamus3d Level 1

                      The code was in the main frame but now i put it on one of the movie clips and got it working.

                      thanks i now slightly get _parent and _root

                      • 8. Re: Hit Test Help
                        Ned Murphy Adobe Community Professional & MVP

                        A _parent is essentially an object that contains things, child objects.  So anytime you need a child to tell its parent what to do, you can talk to it using _parent to target it.   You can try to think of _root as being the _parent of all content in your file, the main timeline.

                         

                        You should avoid using them habitually, and only include them if needed.  Some people use them as if they were taught they need to be used always, and that is not true and can sometimes lead to problems.