?
Solved

Detect when mouse is not over stage

Posted on 2008-06-15
13
Medium Priority
?
5,267 Views
Last Modified: 2013-11-11
Hi guys. I need to be able to detect when the mouse is not over the stage.  The reason being is Im panning and menu vertically with the y  position of the mouse but when the mouse is not over the stage I want the panning to become automatic. I cant figure out how to activate the auto panning. I tried this code which seems logical to me but it doesnt work.

Any ideas?

onEnterFrame = function() {
	if (_ymouse>Stage.height || _ymouse<0 || _xmouse>Stage.width || _xmouse<0) {
		trace("mouse gone");
	}
};

Open in new window

0
Comment
Question by:kalisan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
13 Comments
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 21788817
here is the magic to check if mouse is over Stage or not,,
and it works on AS1 and AS2 both


- Aneesh Chopra
__width = Stage.width;
// stage __width
__height = Stage.height;
// stage __height
/*  extrapolation parameter:
      * Low value (ie <1) = decrease chance of returning out when in
      * High value (ie >1) = decrease chance of returning in when out
      */
extrap = 1;
//-------------------------------//
pointerOut = false;
x0;
x1;
y0;
y1;
dx;
dy;
//
this.onEnterFrame = function()
{
      x1 = _root._xmouse;
      y1 = _root._ymouse;
      if (x1 == x0 && y1 == y0)
      {
            // pointer movement not detected
            // extrapolate to find expected mouse pos and test for inside/outside
            if (x1+extrap*dx<0 || x1+extrap*dx>__width || y1+extrap*dy<0 || y1+extrap*dy>__height)
            {
                  if (!pointerOut)
                  {
                        trace("The mouse has left the movie!");
                  }
                  pointerOut = true;
            }
      }
      else
      {
            if (pointerOut)
            {
                  trace("The mouse has entered the movie!");
            }
            pointerOut = false;
            dx = x1-x0;
            dy = y1-y0;
            x0 = x1;
            y0 = y1;
      }
};

Open in new window

0
 

Author Comment

by:kalisan
ID: 21790977
Hi Aneesh, thx for the code. Only problem is that when I rollover buttons (generated via an XML file) it registeres as mouse leaving stage. Is there a way round this?
0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 21791368
provided code should work perfectly and should not get effected by any button's rollover events..

one point to take care:
above code should be placed on _root of the FLA.

if still it does not work for you.
I request to attached your sample file for review..
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:kalisan
ID: 21795080
Actually, you are right, it doesn't have anything to do with the buttons, that is what I assumed it was but Ive now discovered that if I hover the mouse anywhere towards the bottom of the stage and just move it up and down slightly it registers the mouse going out and coming in quick succession. This basically happens within the bottom third of the stage.

Im getting with in a completely blank FLA with just your script on the root with the stage set to 914 width and 340 height. (CS3, ActionScript 2.0)
0
 

Author Comment

by:kalisan
ID: 21844923
hi Aneesh, have you been able to replicate the above?
0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 21845077
I just tested it and working all fine.... unable to replicate...

one more thing to metion here is, I am using 30 fps for FLA
0
 

Author Comment

by:kalisan
ID: 21862813
Woudl you mind having a look at the attached an let me know what is wrong with it?
0
 

Author Comment

by:kalisan
ID: 21862830
Hmm, wont accept FLA. I've changed my frame rate from 31 to 30 but the bottom part of the stage still registers the mouse going out and coming in quick succession. Weird.
0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 21862843
rename the extention .FLA to .txt and attach it
0
 

Author Comment

by:kalisan
ID: 21862990
cool, here you go...
test.txt
0
 

Author Comment

by:kalisan
ID: 21897028
any luck Aneesh?
0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 21897382
Hi Kalisan,

I tested it using your FLA and agree that discrepency exists if mouse leaves or enters the stage very slowly..
and this seems the limitation of the provided code.

but results are quite good in case of natural mouse movement, (means with realistic mouse speed)
0
 

Accepted Solution

by:
kalisan earned 0 total points
ID: 21897703
Actually what you are getting is not what I was referring to. What is happening with me is that if I move the mouse (little movement) within the bottom third of the stage (i.e. not leaving the stage) it registers going in and out in quick succession. Are you not getting this?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.
Suggested Courses
Course of the Month15 days, 3 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question