20-08-2009

Actionscript3 Handling Mouse Events in AS3

Possible mouse events are :

MouseEvent.CLICK, 
MouseEvent.DOUBLE_CLICK, 
MouseEvent.MOUSE_DOWN, 
MouseEvent.MOUSE_MOVE,
MouseEvent.MOUSE_OUT,
MouseEvent.MOUSE_OVER, 
MouseEvent.MOUSE_UP, 
MouseEvent.MOUSE_WHEEL, 
MouseEvent.ROLL_OUT, 
and MouseEvent.ROLL_OVER.

Quick example on how to handle events / attach listeners to display objects:

import fl.controls.Button;
import flash.events.MouseEvent;
 
var aButton:Button = new Button();
aButton.label = "Submit";
addChild(aButton);
aButton.addEventListener(MouseEvent.CLICK, clickHandler);
 
function clickHandler(evtObj:MouseEvent){
	trace("The " + evtObj.target.label + " button was clicked");
	trace(evtObj.type)
}

Comments:

Your comment:

»

 

[x]