views:

2039

answers:

3

I'm getting an unusual behavior that I can't seem to get to the bottom of. When I run this, if I move in the swf area it traces normally on mouse move. To be expected.

But it's tracing for the move event when I click anywhere on screen. If I click and drag, it traces as if I were moving in the swf area of the browser.

Here's the code. I've simplified to it's barebones. Just put this in in an empty AS3 project in Flex called "Engine" - sans quotes obviously.

package {
import flash.display.Sprite;
import flash.events.MouseEvent;

[SWF(width='640', height='360', backgroundColor='#888888', frameRate='31')]
public class Engine extends Sprite
{       
    public function Engine()
    {
        // Add the mouse handlers
        stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
    }

    public function mouseMoveHandler(evt:MouseEvent):void
    {
        trace("move");
    }
}
}

As a workaround I've add the MOUSE_MOVE one MOUSE_OVER and remove it on MOUSE_OUT. But the behavior still seems quite unusual and I'd be interest in understanding why it's happening.

Can anyone tell me how I can keep the events constrained to the actual stage of the application?

A: 

If you click inside your flash movie and drag the mouse outside of it, MOUSE_MOVE event will continue to trigger until you release your mouse. MOUSE_LEAVE will trigger only when you release the mouse outside the player. This is how Flash Player works.

Maybe I'm wrong but I don't think you can change this behaviour.

PeZ
Yes, that would make sense. This isn't the behavior I'm referring to. If I click *ANYWHERE* on screen... another application, apple bar, whatever... it registers a move event. Even if there's no possible way for Flash to have focus.
grey
Sorry, I can't reproduce this behaviour with your code.Can you post more details like FP version, OS, ...
PeZ
Certainly, sorry for the delay in response.Flash Player Version - Debug, MAC 10,0,22,87
grey
+1  A: 

As already mentioned, you can't stop these events from firing. They are triggered until you release the mouse.

What you can do is compare the coordinates of the MouseEvent with the bounds of the stage and ignore those outside.

public function mouseMoveHandler(evt:MouseEvent):void
{
    if (evt.stageX >= 0 && evt.stageX <= stage.stageWidth &&
        evt.stageY >= 0 && evt.stageY <= stage.stageHeight)
    {
        trace("move");
    }
}
Chadwick
Again. I'm not just talking about when the swf or even the browser has focus. ANY clicks register a move event in any application, any focus.
grey
A: 

Ok, This is a known bug that only happens with Mac.

There is a fix here :

http://www.visible-form.com/blog/transformmanager-fix-for-mac-firefox/

PeZ