-->

hitTestObject on child of a MC

2019-06-06 19:23发布

问题:

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.



标签: flash hittest