Common mistakes when using hitTestPoint function of a DisplayObject
25 April 2009
6 Comments
hitTestPoint is a very usefull function when you want to test if a point (x, y) hits a shape, even an irregular one.
But there are a few but important things that you got to remember to get it to work properly:
- the dispay object you’re working on must be added to the display list.
- use TRUE for the last parameter of the function if you want your point to be tested against the actual shape and FALSE if you just need it to be checked against its bounding box.
- and last but not least, the coordinate space is the Stage’s one. So to get it right, simply use the localToGlobal function on the same display object you’re using the hitTestPoint function and you will get a point object containing the offset/difference for the x and y coordinate.
- Also check if your DisplayObject you want to test a point against is not being used as a mask.









I have been looking for an answer to a bug I have in my game and number 3 was exactly what I needed to find. My hero would fall through the level because I started using a camera. The localToGlobal should fix that though, I think. Many thanks!
Thanks so much! #3 was exactly what I was looking for! How come no one TELLS you these things in the Flash documentation? I was ready to tear my hair out on a client project!
From the Adobe documentation
DisplayObject.hitPointTest()
“Evaluates the display object to see if it overlaps or intersects with the point specified by the x and y parameters. The x and y parameters specify a point in the coordinate space of the Stage, not the display object container that contains the display object (unless that display object container is the Stage). ”
Although a common mistake, it is there in the documentation in plain print.
thanks!!
#2 is very useful to me.
Please send me some examples of #3 as its hard to understand.
Thanks, my problem was #3.
thank you, valuable information^
Leave your response!
Recent Posts
Categories
links
Meta
Recent Comments
Most Commented
Tags
écran de veille 3d 3d model actionscript action script advertising angle animation api array AS3 benchmark bug C++ chess chessanytime class cpp demo digital rain DirectX displayobject event flash font for for each function loop matrix Matrix Fall MovieClip network ocx OpenGL particle effect réseau rotation screensaver socket source source code Visual Basic website whilePowered by eShop v.3
Powered by WordPress | Log in | Entries (RSS) | Comments (RSS) | Arthemia theme by Michael Hutagalung - customized by Thomas John