Learn mouse events with actionscript 3
Hi again all, this time we will take a look at how to "catch" simple mouse events, this might be useful for simple flash menus or games, I made this small example when I was doing a simple flash game and needed the function.
Basically what this flash actionscript tutorial will do is to let you see how to catch the mouse is moving, movie down and mouse up events, and just telling you in a text field, as you can test below.
We will start by making a dynamic text field and give it a name, so with the text tool drag out a text field on the stage, then go the properties panel and change the text type to dynamic (so it can receive info) and give it an instance name. (I named mine "mouse_events").

Now we will go to the actionscript panel and type in some code.
A have made the code description in between the code with comment tags // so you can just delete them if you want.
//These three eventlisteners are telling flash to "listen" for specific events
//in our case if the mouse moves and if the mouse button is down or up.
//then if one of these events happens, it calls a function (mouse_down, mouse_up or moving).
stage.addEventListener(MouseEvent.MOUSE_DOWN, mouse_down);
stage.addEventListener(MouseEvent.MOUSE_UP, mouse_up);
stage.addEventListener(MouseEvent.MOUSE_MOVE, moving);
// This is how to construct a simple function,
// this function will write in our text field "mouse is moving"
// when the even is raised by the eventlistener
function moving(e:MouseEvent)
{
mouse_events.text = "mouse is moving"
}
// function just like above, just for the mouse down event.
function mouse_down(e:MouseEvent)
{
mouse_events.text = "Mouse button is down"
}
// function just like above, just for the mouse up event.
function mouse_up(e:MouseEvent)
{
mouse_events.text = "Mouse button is up again"
}