3
import flash.events.MouseEvent;
4
import flash.display.Sprite;
7
* Implements a common base for button like items. This allows the creation of custom
8
* draw classes far easier than working with Button and simpler than mimic'ing all behaviour.
10
* You must override _resize
11
* It will be called whenever the image might change (status change of some kind). You
12
* may use the down and over variables to determine how to draw the button.
14
class ButtonBase extends Sprite, implements Widget
16
var down : Bool; //the button is in the down position
17
var over : Bool; //the mouse is over the button
19
var event : Action; //the action to perform on clicking
21
function new( event : Action )
33
useHandCursor = true; //look clickable
34
mouseChildren = false; //so added images don't change cursor
36
addEventListener( MouseEvent.MOUSE_DOWN, onMouseDown, false, 0, true /*weak*/ );
37
addEventListener( MouseEvent.MOUSE_UP, onMouseUp,false, 0, true /*weak*/ );
38
addEventListener( MouseEvent.MOUSE_OVER, onMouseOver,false, 0, true /*weak*/ );
39
addEventListener( MouseEvent.MOUSE_OUT, onMouseOut,false, 0, true /*weak*/ );
42
function onMouseDown( evt : MouseEvent )
44
evt.stopPropagation(); //we hide this from our visual ancestors
52
function onMouseUp( evt : MouseEvent )
54
evt.stopPropagation(); //we hide this from our visual ancestors
62
//only handle if we were actually down, to prevent spurious half-events from activating
64
Action.handle( this, event );
67
function onMouseOver( evt : MouseEvent )
70
down = evt.buttonDown;
78
function onMouseOut( evt : MouseEvent )
89
function _resize( w : Float, h : Float )
95
include(`MixinWidget.ihx')