Quick tip: always use global position for hitTestPoint()
Just for the record and myself (I should read all the documentation, also the long sentences
… Make sure you always check hitTestPoint() against global coordinates of some point.
// we are somewhere deep in myObject.myObject2.myInnerObject var point:Point; var someMovingObject:DisplayObject; var hitShape:DisplayObject; point = localToGlobal(new Point(someMovingObject.x, someMovingObject.y)); point = someMovingObject.localToGlobal(new Point()); // both give us same results, // 2nd method is faster in loops while it can use predefined zero point hitShape.hitTestPoint(point.x, point.y, true);
Even hitShape object is not directly on a stage (but on myInnerObject), you have to use global points for testing hits.
The first method may be slower — but even more importantly, it’s not generic.
I mean, if someMovingObject is inside somewhere else, you’d need to do something such as ‘someMovingObject.parent.local..’. Ugly stuff.
@MrKishi, sure thing, thnx for noticing that
Hey Jozef,
would it be possible to show how it would be done when ‘hitShape’ (from your example above) is nested a few movieClips below (my_mc1.my_mc.2.hitShape)?
Thanks!
@rtoprani Hi, what exatcly is function hitShape()? It seems this one does not exist in AS3, anyway you can use hitTestObject() and this one should work no matter where the objects are parented