# Action When Mouse Leaves Flash Movie Area

**URL:** https://forum.kirupa.com/t/action-when-mouse-leaves-flash-movie-area/205073
**Category:** flash
**Created:** [October 25, 2006, 9:51pm UTC](https://forum.kirupa.com/t/action-when-mouse-leaves-flash-movie-area/205073 "2006-10-25T21:51:10Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![MiddleFingerMan](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@MiddleFingerMan](https://forum.kirupa.com/u/MiddleFingerMan)
#### Post date: [October 25, 2006, 9:51pm UTC](https://forum.kirupa.com/t/action-when-mouse-leaves-flash-movie-area/205073/1 "2006-10-25T21:51:10Z")

</div>

Hello All!

I’ve got a flash movie that is a menu with a photo that is approximatly 700x300. I want an action that will trigger when the mouse leaves the flash movie all together. Is this possibe?

Is there a way to have have my movie know when the mouse is not in it and trigger something?

---

<div class="post-metadata">

### Author: ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)
#### Post date: [October 25, 2006, 9:52pm UTC](https://forum.kirupa.com/t/action-when-mouse-leaves-flash-movie-area/205073/2 "2006-10-25T21:52:41Z")

</div>

There is no good way until AS3, so either make the switch now or use a big transparent button.

Or you might be able to use JS to detect when the div the SWF is in loses focus. Not really sure if this is possible though.

---

<div class="post-metadata">

### Author: ![REEF](https://avatars.discourse-cdn.com/v4/letter/r/ce73a5/32.png) [@REEF](https://forum.kirupa.com/u/REEF)
#### Post date: [October 25, 2006, 10:00pm UTC](https://forum.kirupa.com/t/action-when-mouse-leaves-flash-movie-area/205073/3 "2006-10-25T22:00:25Z")

</div>

[QUOTE=TheCanadian;1985502]Or you might be able to use JS to detect when the div the SWF is in loses focus. Not really sure if this is possible though.[/QUOTE]Wouldn’t you have to actually click outside the SWF to lose focus?

---

<div class="post-metadata">

### Author: ![Templarian](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/templarian/32/7152_2.png) [@Templarian](https://forum.kirupa.com/u/Templarian)
#### Post date: [October 25, 2006, 10:01pm UTC](https://forum.kirupa.com/t/action-when-mouse-leaves-flash-movie-area/205073/4 "2006-10-25T22:01:54Z")

</div>

^Yes you would but theres probably a way to check mouse cords and if they change in the JS then the mouse is outside of the flash.

---

<div class="post-metadata">

### Author: ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)
#### Post date: [October 25, 2006, 11:10pm UTC](https://forum.kirupa.com/t/action-when-mouse-leaves-flash-movie-area/205073/5 "2006-10-25T23:10:40Z")

</div>

I used the wrong term, you can use this script to detect when the mouse leaves the div:

In FLA:

```auto
//requires TextField with instance name mouseStatus
import flash.external.ExternalInterface;
ExternalInterface.addCallback("mouseLeave", this, function ():Void {
 this.mouseStatus.text = "mouse is out";
});
ExternalInterface.addCallback("mouseEnter", this, function ():Void {
 this.mouseStatus.text = "mouse is in";
});

```

In HTML:

```auto
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <title>Detecting When Mouse Leaves Stage</title>
  <script type="text/javascript">
   function callEIMethod(name, method) {
    window[name][method]();
   }
  </script>
 </head>
 <body>
   <object onmouseout="callEIMethod('mouseLeaveExample', 'mouseLeave')" onmouseover="callEIMethod('mouseLeaveExample', 'mouseEnter')" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="182" height="118" id="mouseLeaveExample" align="middle">
   <param name="allowScriptAccess" value="sameDomain" />
   <param name="movie" value="mouseLeaveExample.swf" />
   <param name="quality" value="high" />
   <param name="bgcolor" value="#ffffff" />
   <embed src="mouseLeaveExample.swf" quality="high" bgcolor="#ffffff" width="182" height="118" name="mouseLeaveExample" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
  </object>
 </body>
</html>

```

:hoser:

---

<div class="post-metadata">

### Author: ![cooldude88](https://avatars.discourse-cdn.com/v4/letter/c/e0b2c6/32.png) [@cooldude88](https://forum.kirupa.com/u/cooldude88)
#### Post date: [May 13, 2008, 10:46pm UTC](https://forum.kirupa.com/t/action-when-mouse-leaves-flash-movie-area/205073/6 "2008-05-13T22:46:47Z")

</div>

okay everyone is getting extremly complex for no reason why not something like  
if(\_xmouse\<=5 or \_xmouse\>=690){  
/_actions_/  
}  
would that not work if you just went a little bit inside of the borders and repeat that code for both x and y mouse coordinates. i dont see why that wont work.

---

<div class="post-metadata">

### Author: ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)
#### Post date: [May 13, 2008, 11:11pm UTC](https://forum.kirupa.com/t/action-when-mouse-leaves-flash-movie-area/205073/7 "2008-05-13T23:11:21Z")

</div>

Sticking with the big invisible button/movieclip is easiest as it avoids any cross-browser issues, and makes it simple to trigger events.

> **[A mouse-focus based pause function for a game?](https://www.kirupa.com/forum/showthread.php?t=290858)**
>
> Got a web design/development question or just want to hang out with the most awesome people on the planet? Drop on in!
