hitTestObject on child of a MC

此生再无相见时 提交于 2019-12-23 02:59:21

问题


I have a MC called 'playerP" and inside of it with 7 different MC. I can't seems to hit test on the children MC, it always show [object position_2]

private function cMove(e:MouseEvent):void
        {
            trace(MovieClip(playerP.RR), playerP.PT)
            if (e.currentTarget.hitTestObject(playerP.PT))
            {
                trace("hit la");
            }
        }

回答1:


Try explicitly iterating through the children.

private function cMove(e:MouseEvent):void
    {
        for (var ii : uint = 0; ii < playerP.numChildren; ++ii)
        {
            if (e.currentTarget.hitTestObject(playerP.getChildAt(ii)))
            {
                trace("hit la");
            }
        }
    }



回答2:


I am trying to reference a movieclip that has 2 layers and 2 instance references. One is called Erik, the other hit. Currently the larger Erik is working, how can I make 'hit' be the target.

for (var ii : uint = 0; ii < target.numChildren; ++ii) {
    if (e.currentTarget.hitTestObject(target.getChildAt(ii))){
        trace("hit la");
    }
}

This works but on Erik which is set by

public function Catcher(stageRef:Stage, target:Erik) : void

as Erik is a class object.



来源:https://stackoverflow.com/questions/4703863/hittestobject-on-child-of-a-mc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!