ShapeButton

A button widget with a slightly raised look and an optional graphics shape placed above an optional label text.

See also

BubbleButton, LabelButton, ToggleButton.

Summary
ShapeButtonA button widget with a slightly raised look and an optional graphics shape placed above an optional label text.
Private display constants
LABEL_MARGINSmall margin to keep the text label from the button border.
DEFAULT_WIDTHDefault button width
DEFAULT_HEIGHTDefault button height
Private display members
cornerSizeRounded corner size.
Private state members
downStateSprite displayed when the button is pressed.
upStateSprite displayed when the button is not pressed.
lastStateLast state the button has been in.
Private data members
callbackCallback function called when the button is clicked or auto-repeats.
timerTimer used when the button auto-repeats.
repeatRepeat interval in milliseconds.
Constructor
ShapeButtonCreates a button with a graphics shape and/or a label text.
Public properties
nameSets the display object instance name for all the parts of the button.
Mouse event methods
mouseDownHandlerCalled when the mouse button is pressed.
mouseUpHandlerCalled when the mouse button is released.
mouseOutHandlerCalled when the mouse is moved away from the button.
Auto-repeat methods
startStart auto-repeating clicks on the button.
stopStops and removes the auto-repeat timer.
timerHandlerHandles the timer callback for auto-repeat of the button.
Private display methods
resizeTextCenters the text on the button.
getBitmapFilterGets a bevel bitmap filter to give the button a raised look.
WidgetInterface
activeSets the state of the widget to active or inactive.
activateActivates the widget, adds its event listeners
disactivateDisactivates the widget, removes its event listeners
disposeDispose of all resources used or referenced in the instance.
destructorRemoves used resources, references and graphics

Private display constants

LABEL_MARGIN

private const LABEL_MARGIN: uint

Small margin to keep the text label from the button border.

DEFAULT_WIDTH

private const DEFAULT_WIDTH: uint

Default button width

DEFAULT_HEIGHT

private const DEFAULT_HEIGHT: uint

Default button height

Private display members

cornerSize

private var cornerSize: uint

Rounded corner size.  Rounded corners are only used if the button size is at least the double of the corner size.

Private state members

downState

private var downState: Sprite

Sprite displayed when the button is pressed.

upState

private var upState: Sprite

Sprite displayed when the button is not pressed.

lastState

private var lastState: DisplayObject

Last state the button has been in.

Private data members

callback

private var callback: Function

Callback function called when the button is clicked or auto-repeats.

timer

private var timer: Timer

Timer used when the button auto-repeats.

repeat

private var repeat: int

Repeat interval in milliseconds.

Constructor

ShapeButton

public function ShapeButton(owner: String,  
upShapeFunction: Function,  
downShapeFunction: Function,  
labelText: String = null,
color: uint = Color.Grey,
clickHandler: Function = null,
buttonWidth: Number = DEFAULT_WIDTH,
buttonHeight: Number = DEFAULT_HEIGHT,
autoRepeat: int = 100)

Creates a button with a graphics shape and/or a label text.  Thebutton has up/down states and auto-repeat capability.  The up/downShapeFunction signatures are: function createShape():Shape.  The clickHandler callback signature is: function clickHandler():void.

Parameters

ownername of registered owner; see WidgetSprite.register
upShapeFunctionfunction returning a graphics shape for the button up state
downShapeFunctionfunction returning a graphics shape for the button down state
labelTexttext string to be placed on the button
colorbase theme color for the button
clickHandlera callback function that is called when the button has been clicked
buttonWidthwidth of the button (default 70 pixels)
buttonHeightheight of the button (default 20 pixels)
autoRepeatmilliseconds between auto-repeat events, set to -1 to disable (default 100)

Callbacks

clickHandlerfunction onShapeButtonClick():void

Public properties

name

public override function set name(labelName: String):void

Sets the display object instance name for all the parts of the button.  This is so tooltips can be displayed without flicker when moving over the button.

Mouse event methods

mouseDownHandler

private function mouseDownHandler(event: MouseEvent):void

Called when the mouse button is pressed.  Changes the button to the down state and starts the auto-repeat timer if its interval is set to zero or larger.  An auto-repeat value of -1 therefore disables auto-repeat.

Parameters

eventa mouse event

mouseUpHandler

private function mouseUpHandler(event: MouseEvent):void

Called when the mouse button is released.  Stops auto-repeat actions and raises the button to the up state.  Calls the button callback handler.

Parameters

eventa mouse event

mouseOutHandler

private function mouseOutHandler(event: MouseEvent):void

Called when the mouse is moved away from the button.  Stops auto-repeat actions and raises the button to the up state.

Parameters

eventa mouse event

Auto-repeat methods

start

private function start(interval: uint):void

Start auto-repeating clicks on the button.

Parameters

intervalmilliseconds between updates

stop

private function stop():void

Stops and removes the auto-repeat timer.

timerHandler

private function timerHandler(event: TimerEvent):void

Handles the timer callback for auto-repeat of the button.

Parameters

eventa timer event

Private display methods

resizeText

private function resizeText(textLabel: Label,
buttonWidth: Number,
buttonHeight: Number):void

Centers the text on the button.  If the text is wider than the button then it is scaled down to fit.

Parameters

textLabeltext label placed on the button
buttonWidthwidth of the button
buttonHeightheight of the button

getBitmapFilter

private function getBitmapFilter(color: uint):BitmapFilter

Gets a bevel bitmap filter to give the button a raised look.

WidgetInterface

active

public function set active(state: Boolean):void

Sets the state of the widget to active or inactive.

Parameters

stateTrue to activate, false otherwise.

activate

private function activate():void

Activates the widget, adds its event listeners

disactivate

private function disactivate():void

Disactivates the widget, removes its event listeners

dispose

public function dispose():void

Dispose of all resources used or referenced in the instance.

destructor

private function destructor():void

Removes used resources, references and graphics

Widgets are required to implement this interface.
Base class for widgets to enable/disable event listeners and keep a global tab order of all widgets (provided they are created and registered in tab order.
private const LABEL_MARGIN: uint
Small margin to keep the text label from the button border.
private const DEFAULT_WIDTH: uint
Default button width
private const DEFAULT_HEIGHT: uint
Default button height
private var cornerSize: uint
Rounded corner size.
private var downState: Sprite
Sprite displayed when the button is pressed.
private var upState: Sprite
Sprite displayed when the button is not pressed.
private var lastState: DisplayObject
Last state the button has been in.
private var callback: Function
Callback function called when the button is clicked or auto-repeats.
private var timer: Timer
Timer used when the button auto-repeats.
private var repeat: int
Repeat interval in milliseconds.
public function ShapeButton(owner: String,  
upShapeFunction: Function,  
downShapeFunction: Function,  
labelText: String = null,
color: uint = Color.Grey,
clickHandler: Function = null,
buttonWidth: Number = DEFAULT_WIDTH,
buttonHeight: Number = DEFAULT_HEIGHT,
autoRepeat: int = 100)
Creates a button with a graphics shape and/or a label text.
public override function set name(labelName: String):void
Sets the display object instance name for all the parts of the button.
private function mouseDownHandler(event: MouseEvent):void
Called when the mouse button is pressed.
private function mouseUpHandler(event: MouseEvent):void
Called when the mouse button is released.
private function mouseOutHandler(event: MouseEvent):void
Called when the mouse is moved away from the button.
private function start(interval: uint):void
Start auto-repeating clicks on the button.
private function stop():void
Stops and removes the auto-repeat timer.
private function timerHandler(event: TimerEvent):void
Handles the timer callback for auto-repeat of the button.
private function resizeText(textLabel: Label,
buttonWidth: Number,
buttonHeight: Number):void
Centers the text on the button.
private function getBitmapFilter(color: uint):BitmapFilter
Gets a bevel bitmap filter to give the button a raised look.
public function set active(state: Boolean):void
Sets the state of the widget to active or inactive.
private function activate():void
Activates the widget, adds its event listeners
private function disactivate():void
Disactivates the widget, removes its event listeners
public function dispose():void
Dispose of all resources used or referenced in the instance.
private function destructor():void
Removes used resources, references and graphics
An action button drawn as a bubble with an optional symbol on top.
A button widget with a slightly raised look and a label text on it.
A switch button with an on and off state.
public function register(owner: String):void
Register the owner of a widget.
Close