views:

21

answers:

1

Google says that:

displayObject.hitTest(stage.mouseX, stage.mouseY, true)

is the way to test for the mouse being over a DisplayObject. This works if my movie is displayed at 100% scale. But if maximise my browser window so the Flash movie changes scale, it all goes to pieces.

Does anyone have a way to fix this, please?

Many thanks.

+1  A: 

I normally use:

 stage.addEventListener(MouseEvent.MOUSE_OVER, functionName);

But, if you have a specific reason for using the hitTest method, than you may want to look into converting your point from a global to a local MovieClip coordinate. Once you scale a MovieClip, it's x-y coordinates are no longer mapped 1-to-1 to the stage coordinates. BUT, you can make Flash figure out which coordinate you ARE talking about by using:

 yourMovieClip.globalToLocal( yourTestPoint )); // [x=-10, y=0]

Here is the related link with all the documentation...

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObject.html

You may also want to take a look at the "hitTestObject()" method which does the same thing as hitTestPoint, only using the entire object... no points!

hope this helps.

exoboy
Thanks for your answer. As you say, the issue is that when the movie is scaled up (in a maximised browser window say), the co-ordinates of my outermost movie clip don't match those of the stage. So, seemingly contrary to the docs, I need to use the co-ordinate space of my outermost DisplayObject for the hit test, as below: var point:Point = new Point (e.stageX, e.stageY); point = outerMostDisplayObject.globalToLocal(point); if (hitArea.hitTestPoint(point.x, point.y, true)) {}
tarling