Game Development Reference
In-Depth Information
What are the events we can handle in Flash?
Among plenty of mouse events that Flash offers, let us talk about a few important
ones here:
Event
Description
CLICK
When the mouse was clicked on a sprite
MOUSE_OVER
When the mouse moves over a sprite
MOUSE_OUT
When the mouse moves out of bounds of a sprite
MOUSE_MOVE
When the mouse moves around within the bounds of a sprite
MOUSE_DOWN
When primary mouse button is held down within the bounds
of a sprite
MOUSE_UP
When the primary mouse button is released within the bounds
of a sprite
For a complete list of mouse events, please refer to Flash framework documentation.
The event definitions are defined in the MouseEvent class in flash.events .
Try the following example and experiment how and when Flash fires those callbacks
for the previous mouse events. You are encouraged to add more callbacks to other
mouse events that are not mentioned here:
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
public class MouseEvents extends Sprite
{
public function MouseEvents()
{
var s:Sprite = new Sprite();
s.graphics.beginFill(0xFFFF00);
s.graphics.drawCircle(0, 0, 10);
s.graphics.endFill();
s.addEventListener(MouseEvent.CLICK, onMouseClick);
s.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
s.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
s.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
s.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
s.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
addChild(s);
}
private function onMouseClick(e:MouseEvent):void {
trace("onMouseClick");
Search WWH ::




Custom Search