6 Replies Latest reply on Jan 17, 2010 5:29 PM by kglad

    hitTest for rect shape mc within irreg shape on 2nd mc

    L_B_ Level 1

      I have looked everywhere I can think of for a solution to this problem. It seems like it should be so simple, but I can't figure out what Flash/AS calls what I'm trying to do. I would be very grateful for any help that anyone can give ...

       

      In my app, a user must drag and release a rectangular mc object (rectx) over an irregular shape within another mc object (irregx). There are 13 rect/irreg

      pairs. Each obj shares an AS2 file that checks whether rectx is over irregx, and proceeds _only_ if the check is true. 

       

      The script uses hitTest, on mouse release, to grab the number (x) of the rectx being dragged and checks whether it's over irregx. Right now, the check comes back true when rectx is _anywhere_ inside irregx's bounding box whether it's over the actual image or not.

       

      I've noticed that, when the (unpressed) mouse rolls over any irregx, it's oblivious to irregx's rectangular bounding box. It only reacts when it reaches the edge of the irregular shape inside, toggling from arrow to hand at the image edges.

       

      Since the mouse knows where the irregx image boundary is, is there a simple way to tap the mouse's 'eyesight' to verify whether rectx is over the correct irregx shape (meaning not just within the bounding box, within the shape inside it)?  This can't be that hard. I clearly haven't learned enough about AS2. Thanks very much. Best regards, L

       

        • 1. Re: hitTest for rect shape mc within irreg shape on 2nd mc
          kglad Adobe Community Professional & MVP

          yes, if you check the _droptarget of any dragged movieclip, the object under the mouse (if any), when the mouse is released, is returned.

          1 person found this helpful
          • 2. Re: hitTest for rect shape mc within irreg shape on 2nd mc
            Rothrock Level 5

            The _droptarget property will return the object under the mouse, but I think what the OP really wants is a shape based hit detection.

             

            This can be done using an external class like gSkinner's collision detection class. Such tests are usually a little expensive in terms of processor, so you could use the built in flash tests to see if the bounding boxes are colliding and then pass a list of the suspected ones to determine if they are actually hitting.

            • 3. Re: hitTest for rect shape mc within irreg shape on 2nd mc
              kglad Adobe Community Professional & MVP

              you get a shape-based hittest using the _droptarget as long as you're willing to accept the mouse position as determining the hitTest() parameter (as contrasted with the dropped object).   and that seems to be exactly his point because he realizes mouse handlers are shape-based.

               

              p.s.  the two shape-based hittests i'm familiar with (skinner's and mine) already check for the the standard hittest (or its equivalent) before using a bitmapdata hittest.  you don't need to do that before calling the shape-based test.

              1 person found this helpful
              • 4. Re: hitTest for rect shape mc within irreg shape on 2nd mc
                L_B_ Level 1

                 


                sorry for the delay. the response email said 'reply' to post. i did. it bounced back ...

                 

                kglad,  you so rock.

                 

                _droptarget works perfectly as long as the cursor is within the irreg. some irregs are smaller than their corresponding rect. so, part of rect can be over irreg, but not always the part containing the cursor.

                 

                if i knew what i was doing, i imagine i could ask the mouse to get the full perimeter of the rect it's carrying and check to see whether any part of the rect is over the irreg.

                 

                i may have to redesign the interaction employing a proxy for the rect that is smaller than the smallest irreg. not ideal, but i think i have a better shot at being able to program that.

                 

                thank you so much.

                 

                -------------------

                 

                 

                rothrock,

                 

                i appreciate your thought on collision detection classes. i've looked at gSkinner's info. it's a little over my head, i'm swapping variables in as2, but haven't imported classes yet. i'm going to keep scowering what's there to see whether I can learn something that will help. i'm going to try to find kglad's now. thanks for your help.

                 

                best, L

                • 5. Re: hitTest for rect shape mc within irreg shape on 2nd mc
                  Rothrock Level 5

                  I'm glad that worked out for you. Remember that hitTest comes in two flavors. One is for movieclip bounding box against movieclip bounding box. But the other is to use movieclip against a point. Since the position of the mouse is a point (at a given x and y) then you can use that second approach as well.

                   

                  myClip.hitTest(_xmouse,_ymouse,true);

                   

                  The third parameter also provides the ability to check either bounding box or actual pixel hit. So you can add that as one more technic at your disposal.