Solved

Detect when mouse is not over stage

Posted on 2008-06-15
13
5,235 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
  • 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
 

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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
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): …
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now