3 Replies Latest reply on May 15, 2009 5:59 AM by flashiseasy

    problem with hitTest on multiple Mcs

    flashiseasy

      If anyone can help, I would be most grateful.

      I have a movie clip called frog who moves along the screen, I want him to jump when he hits any other movie clips. I can make him do so with the code below, the problem is that if I write the same function for the other movie clips it doesnt work, it still works on the first one but none others. I have tried attaching an onCilpEvent on both the frog and on all the other movie cilps so no avail.

       

      function hitBaby(){

       

          if(_root.babyWord.hitTest(_root.frog)){

       

          _root.frog.gotoAndPlay("frogB");
      }
      else{
          _root.frog.gotoAndPlay("frogA");
      }

       

      }

       

      Thanks in advance for any suggestions.

      Tina

        • 1. Re: problem with hitTest on multiple Mcs
          RossRitchey Level 4

          flashiseasy wrote:

           

          the problem is that if I write the same function for the other movie clips it doesnt work

          1. What do you mean by this... are you trying to make other clips jump, or testing the frog for other hitTests?

          2. What happens when "it doesnt work"?  Does it give you an error, if so, please post it.  If not, what happens?

          • 2. Re: problem with hitTest on multiple Mcs
            MaxManNH Level 2

            It looks to me like you are attempting a simple hitTest loop.

             

            function hitBaby()

            {

                 for(var index:Number = 0; index < someNumber; index++)

                 {

                      if(_root["babyword" + index].hitTest(_root.frog))

                      {

                          _root.frog.gotoAndPlay("frogB");
                      }
                      else

                      {
                          _root.frog.gotoAndPlay("frogA");
                      }

                 }

            }    

             

            So you loop through all the babyWord movieclips that are named babyWord1 babyWord2 etc.. and check for the hitTest. You will probably want this code in an enterFrame event on the maintimeline or in a setInterval function. Remember that someNumber needs to be the highest number in your range of babyWord movieclips so it will check them all.

            • 3. Re: problem with hitTest on multiple Mcs
              flashiseasy Level 1

              thanks for your reply. To try and clarify:

              I want the mc called frog to hitTest a number of movie clips (26 in all) so that if the hittest is true the frogMc plays another frame (which makes him jump). I dont get any error messages, what happens is that the hitTest only works on one movie clip, I put a trace on another which didnt detect even the trace.

              thanks again

              Tina