3

I just tossed this super simple code example into a Flash CS4 IDE frame script, but it doesn't output anything in the console. I'm simply rolling over my mouse over the window, not clicking anything, and nothing is happening. Why doesn't this work as I expect?

stage.addEventListener(Event.MOUSE_LEAVE, traceMouse);

function traceMouse(Evt:Event):void
 {
 trace("Mouse Left Stage");
 }

________________________________________________

[EDIT] i find Event.MOUSE_LEAVE incredibly useless. first, it doesn't work in the testing environment (on Flash CS4 for Mac OS X, at least). second, it doesn't fire if MouseEvent.MOUSE_DOWN is currently active:

Flash CS4 Professional ActionScript 3.0 Language Reference:

Updated 8/11/09: Added qualification that event is not fired when button is pressed.1

in my particular situation, i wanted MOUSE_LEAVE to fire while i was dragging an object so that in the event the user drags his/her mouse pointer off of the stage it would fire stopDrag(). since that's not possible i've decided to use MOUSE_OUT on the actual object rather than MOUSE_LEAVE on the object's parent or stage.

 private function mouseDownHandler(evt:MouseEvent):void
  {
  object.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
  object.startDrag(false, pullBounds);
  }

 private function mouseUpHandler(evt:MouseEvent):void
  {
  object.removeEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
  object.stopDrag();
  }

 private function mouseOutHandler(evt:MouseEvent):void
  {
  object.stopDrag();
  }
Chunky Chunk
  • 16,553
  • 15
  • 84
  • 162
  • It works in the Flash CS4 IDE for me (Win XP) but the fact it doesn't work while mouse is pressed makes it totally useless. Adobe is really annoying me these days. BTW where did you find the note? That link doe's not work. – daniel.sedlacek Apr 12 '11 at 16:57
  • it was written in the 10.0 documentation for Flash 10.1 under flash.display.Stage.mouseLeave, but they seem to have removed it. – Chunky Chunk Apr 13 '11 at 02:42

2 Answers2

3

Here's a couple additional tricky things to know (when running in a browser) :

One bizarre thing is that in Chrome + Firefox, the MOUSE_LEAVE event isn't dispatched for a WMODE of OPAQUE orTRANSPARENT. It just doesn't fire - mouse down or up.

With WINDOW it works fine. That one took me a long time to find out! grr... http://bugs.adobe.com/jira/browse/FP-892


Second, make sure you're using Event for the parameter type for your Event.MOUSE_LEAVE handler and not MouseEvent. If you try to handle MOUSE_LEAVE with e:MouseEvent you'll get an error that you may never see (unless you're using the debug flash player). It's a very easy mistake to make because you're probably pointing all your other handlers to the same method.

Here's what I do: (just call my main endDrag from mouseLeave(e:Event)

stage.addEventListener(MouseEvent.MOUSE_MOVE, drag);
stage.addEventListener(MouseEvent.MOUSE_UP, endDrag);
stage.addEventListener(Event.DEACTIVATE, endDrag);
stage.addEventListener(Event.MOUSE_LEAVE, mouseLeave);

private function mouseLeave(e:Event):void
{
    endDrag(new MouseEvent("MOUSE_LEAVE"));
}

public function endDrag(evt:MouseEvent):void
{
    /// handle end drag
}
Community
  • 1
  • 1
Simon_Weaver
  • 140,023
  • 84
  • 646
  • 689
  • 1
    @TheDarkIn1978 I realize you didn't make the second mistake here - but I always forget this and it can be easy to miss – Simon_Weaver May 18 '11 at 19:59
1

I don't think this specific event works in the authoring environment, try publishing a html wrapper and running it in your browser.

grapefrukt
  • 27,016
  • 6
  • 49
  • 73
  • before posting i googled this issue. it seems that some people can't get it to work with the IDE, while others think they are crazy and it works for them no problem. could it possibly be a setting? and yes it does work for me when published in a browser – Chunky Chunk Apr 07 '10 at 21:23
  • 1
    It might be OS dependent or something, I stay as far away as I can from flash authoring for code type stuff, so I never really run into this. – grapefrukt Apr 07 '10 at 21:59
  • that's a smart theory. i wouldn't be surprised if you were correct since MouseEvent.MOUSE_WHEEL doesn't work at all on Mac OS X (which is what i'm using) – Chunky Chunk Apr 07 '10 at 22:27