I saw some people asking about it, so… here’s the answer.
In the AS3, when you need to know if the mouse leaves the Stage, you just have to add the Event.MOUSE_LEAVE to it.
UPDATE: I’ve created an example, so you can see how it works.
Create a new Flash File (AS3), set the Stage size to 200×200 (if you want, sure). Create a simple square, with the color 0×00CCCC, convert it to a MovieClip object, and set the instance name of square Click on the Stage, and set the Document Class (in the properties panel) to app.Application. The Application class will take care of anything that we’ll need on our FLA file.
So, create a new folder on the same place that you saved your FLA file, and call it app. Back to the Flash enviroment, create a new ActionScript File, and save it on the app folder, with the name of Application.
Here’s the code of the Application file:
[sourcecode language='actionscript']package app
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.ColorTransform;
import flash.geom.Transform;
public class Application extends MovieClip
{
/**
* Constructor.
*/
public function Application()
{
super();
// When mouse overs the stage.
this.stage.addEventListener(MouseEvent.MOUSE_OVER, this.mouseOverHandler);
// When mouse leaves the stage.
this.stage.addEventListener(Event.MOUSE_LEAVE, this.mouseLeaveHandler);
}
/**
* Change the square color.
*
* @param color The color hexadecimal value.
* @return void
*/
public function changeSquareColor(color:uint):void
{
// The transform object of the square object.
var oTransform:Transform = new Transform(this.square);
// The color transform object.
var colorTrans:ColorTransform = new ColorTransform();
// Setting the new color.
colorTrans.color = color;
// Applying the color changes.
oTransform.colorTransform = colorTrans;
}
/**
* Handler of the Event.MOUSE_LEAVE event.
*
* @param evt The event object.
* @return void
*/
private function mouseLeaveHandler(evt:Event):void
{
this.changeSquareColor(0xFF0000);
}
/**
* Handler of the MouseEvent.MOUSE_OVER event.
*
* @param evt The event object.
* @return void
*/
private function mouseOverHandler(evt:MouseEvent):void
{
this.changeSquareColor(0×00CCCC);
}
}
}[/sourcecode]
To see this working, you need to add your SWF file to an HTML file.
You can download the files here: http://www.mozartpetter.com/downloads/MOUSE_LEAVE.zip
Good read, thanks for the information, it was really informative.
looking forward for more information about this. thanks for sharing. Eugene