开发者

hitTestPoint not giving correct results

I have a movie clip on which I have added a MouseEvent.MOUSE_OUT listener.

movieclip.addEventListener(MouseEvent.MOUSE_OUT, removeMovieClip);

Now the logic is to remove the movie clip on MOUSE_OUT and add it back to stage on MouseOver of another button. The intended functionality is like a slider showing some info

The MouseEvent.MOUSE_OUT firing in this case is not functioning always as expected. When I move the mouse out of the moveclip fast it fires. If I moveout very slowly it does not fire and consequently the movieclip remains on the stage.

What could be the problem? .

Update: I forgot to mention that I use hitTestPoint to test if the mouse is outside of the MovieClip. In most of the cases if I move the mouse slowly, hitTestPoint does not give the correct results(false) that it’s outside of the Movieclip and hence I cannot remove the object.

Update 2: Let me rephrase the question. I think I have messed up the explanation.

The Mouse events work correctly.

movieclip.addEventListener(MouseEvent.MOUSE_OUT

fires correctly and I am in the event handled method. Now when I try to ascertain whether I am out of this MovieClip is when the problem arises.

private function removeObj(eve:Event):void开发者_运维问答
{
    var e:MouseEvent = MouseEvent(eve);
    if (m_wishlistImage)
    {
        var InsideSlot:Boolean = eve.currentTarget.hitTestPoint(e.stageX, e.stageY);
        if(!InsideSlot){

While moving the mouse slowly out of the object InsideSlot remains true and hence the code flow does not go inside the if condition and consequently I am unable to remove the object.

While tracing e.stageX I see that it often shows coordinates which is not exactly where the mouse is when it moved out (shows a point inside the slot). This behaviour shows up most often when I slowly move out.

What could be the reason?


Check that your mouse position is in stage coordinates (NOT your child movieclip coordinates).

In other words make sure you are using stage.mouseX, stage.mouseY as opposed to implicitly using the local member variables inside the movieclip (which will give the mouse position relative to the movieclip.)

hitTestPoint requires the point to be given as stage coordinates.


Well this problem can be solved if you replace your code of MouseEvent.MOUSE_OUT to Event.ENTER_FRAME event. You need to use it because mouse-Movements are not captured sometimes in Mouse-Event listeners also because swf frame-rate is normally too faster to track mouse movements so use Event.ENTER_FRAME.

And i have faced such kind of problem before. So add listener to stage like this

addEventListener(Event.ENTER_FRAME,removeMovieClip)

Now before removing an object or movieClip from container , put checks also like

public function removeMovieClip(evt:Event):void

{

If(ParentClip.contains(ChildClip)) ParentClip.removeChild(ChildClip)..

}


try listening to the MouseEvent.ROLL_OUT event, instead.


If your MovieClip's mouseChildren property is not set to false, it is plausible that you are triggering the MOUSE_OUT event before you expect to depending on the contents of the MovieClip.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜