Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Hittest triggers underlying movieclips

Community Beginner ,
Mar 18, 2014 Mar 18, 2014

Hi

I also posted this on another forum. Hope this one is a bit more active still.

I can't seem to figure this one out.

I have a simple for loop that activated when a stopDrag has been triggered.

this checks if my dragable object hits the part i want.

It does work however it also hittests on the movieclip that is underneath it. oddly enough if 3 clips overlap, they all trace out their name.

Each movieclip, about 13 in total, overlap each other, a few don't, those who don't overlap work perfectly.

I tried mouseChildren false;


Does anyone have an idea? Maybe I am just tired but I can't seem to grasp what is going on.

Many thanks in advance.


here a flint of the code where relevant

      private function release(event: MouseEvent): void {

         event.target.stopDrag();

         for (var k: int = 0; k < whichclips.length; k++) {

            whichclips.mouseChildren = false;

            if (hitTestMouse(whichclips)) {

               trace("hitTest " + whichclips.name);

            }

         }

      }


      public function hitTestMouse(hitarea: DisplayObject): Boolean {

         return hitarea.hitTestPoint(hitarea.stage.mouseX, hitarea.stage.mouseY, true);

      }


TOPICS
ActionScript
483
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Mar 18, 2014 Mar 18, 2014
LATEST

Looking over your code there appear to be some hickups:

1. You most likely want to use currentTarget instead of target in any thing that deals with hit detection

2.You are using the wording "hitarea" in your hitTestMouse function that is almost undistinguishable from the "native" one

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Sprite.html#hitArea

This is not advised, always clearly distinguish your "created" code from the core classes/properties

3.Read up on hitTestPoint

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObject.html#...

The moment you have nested MovieClips it gets messy real fast (see Example)

I don`t understand why you would choose this method over hitTestObject, which will make your job way easier.

Also: Flashs Built in Colllision detection has a lot of caveats, if you have many "irregular" objects you will have to go the extra mile:

http://www.freeactionscript.com/2011/08/as3-pixel-perfect-collision-detection/

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines