简体   繁体   English

hitTestPoint()shapeFlag在包含已加载的swf的movieClip上不起作用

[英]hitTestPoint() shapeFlag not working on movieClip containing loaded swf

I have a .swf file containing a circle that I load from a URL, make into a movieClip and add it to the stage. 我有一个.swf文件,其中包含一个从URL加载的圆圈,并放入movieClip中并将其添加到舞台中。

I would like to be able to detect when the user places the cursor over the circle. 我希望能够检测到用户何时将光标放在圆圈上。 I'd like it to be accurate in a sense that it doesn't simply use the bounding box of the circle, but the actual circle itself to detect a collision. 从某种意义上讲,我希望它是准确的,它不只是使用圆的边界框,而是使用实际的圆本身来检测碰撞。 This is a fragment of my current code: 这是我当前代码的一部分:

    //
    var myCircle:MyCircle = new MyCircle(swf);
    myCircle.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
    myContainer.addChild(myCircle);
    //

    private function onMouseMove(event:MouseEvent):void
    {
        var glowFilter:GlowFilter = new GlowFilter();
        glowFilter.color = 0xffffff;
        if (event.currentTarget is MyCircle) {
            var object:MyCircle = event.currentTarget as MyCircle;
            if(object.hitTestPoint(event.stageX, event.stageY, true))
                event.currentTarget.filters = [glowFilter]; 
            else
                event.currentTarget.filters = []; 
        }
    }

I was led to believe that the shapeFlag parameter to the hitTestPoint() method would do this, but setting it either true or false makes no difference. 我被认为是hitTestPoint()方法的shapeFlag参数可以做到这一点,但是将其设置为true或false都没有区别。 Any ideas why this might be? 任何想法为什么会这样?

I wrote a very short blog post about this earlier so I had it for future times... 我在较早的时候写了一篇很短的博客文章,所以我以后会用到它。

It seems like you are looking at stageX which AFAIK is the global x-coordinate of the object. 似乎您正在查看stageX,该AFAIK是对象的全局x坐标。

http://messer1024.blogspot.se/2012/06/proper-hittest-in-as3.html http://messer1024.blogspot.se/2012/06/proper-hittest-in-as3.html

Short version of a short post: 简短帖子的简短版本:

After many ugly attempts at handling hit tests in AS3 I finally managed to solve what I was looking for. 经过在AS3中处理击键测试的许多丑陋尝试之后,我终于设法解决了我所寻找的问题。 The thing I forgot to consider was to use the global mouse-coordinates. 我忘了考虑的事情是使用全局鼠标坐标。

public function hitTestMouse(hitarea:DisplayObject):Boolean {
    return hitarea.hitTestPoint(hitarea.stage.mouseX, hitarea.stage.mouseY, true);
}

The last parameter (shapeFlag) would decide if the hit test are checked any actual shapes inside the hitarea that the mouse is hovering above. 最后一个参数(shapeFlag)将决定是否检查点击测试,鼠标悬停在点击区域内的任何实际形状。


So in order for your thing to work, you should probably make it a bit easier and add my function and then run "hitTestMouse(myCircle)" when you feel like testing it 因此,为了使您的东西正常工作,您可能应该使它更容易一些,并添加我的函数,然后在您想对其进行测试时运行“ hitTestMouse(myCircle)”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM