BubbleButton

An action button drawn as a bubble with an optional symbol on top.  Use of this class should be deprecated, use ShapeButton instead.

Events are intercepted in the capture phase meaning that target testing must be performed in the class where the buttons are used.

See also

LabelButton, ShapeButton, ToggleButton.

Example

// Add/remove/handle a close button centered on a Sprite

import flash.events.MouseEvent;
var closeButton:BubbleButton = null;

// Add button
closeButton = new BubbleButton(mouseCloseHandler, bgColor, BubbleButton.SYMBOL_X);
closeButton.name = "CloseButton";
closeButton.x = width/2 - closeButton.width/2;
closeButton.y = height/2 - closeButton.height/2;
addChild(closeButton);

// Remove button
if (closeButton != null)
{
    closeButton.dispose();
    closeButton = null;
}

// Handle button press
private function mouseCloseHandler(event:MouseEvent):void
{
    // Perform action
}

Using flash.display.SimpleButton consumed an excessive amount of CPU when a dozen of instances (FP9r16) were used so all use of SimpleButton has been eliminated.

Summary
BubbleButtonAn action button drawn as a bubble with an optional symbol on top.
Public constants
DEFAULT_SIZEDefault button diameter in pixels
SYMBOL_NONENo symbol is drawn on the button
SYMBOL_XAn X symbol (close) is drawn on the button
SYMBOL_DOTA dot is drawn on the button
SYMBOL_CIRCLEA circle is drawn on the button
private data members
downStateVisual state of the button when it is pressed down
overStateVisual state of the button when the mouse hovers over it
upStateVisual state of the button when it is unselected
lastStateLast active visual state of the button
callbackFunction called when the button is clicked
Constructor
BubbleButtonCreates a button drawn as a bubble.
Event Handlers
mouseDownHandlerChange state when the button is pressed
mouseUpHandlerChange state when the button is released
mouseOutHandlerChange state when the mouse is moved away from the button
mouseOverHandlerChange state when the mouse is over the button
mouseClickHandlerButton click handler calls back to user supplied handler if present
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

Public constants

DEFAULT_SIZE

public static const DEFAULT_SIZE: uint

Default button diameter in pixels

SYMBOL_NONE

public static const SYMBOL_NONE: uint

No symbol is drawn on the button

SYMBOL_X

public static const SYMBOL_X: uint

An X symbol (close) is drawn on the button

SYMBOL_DOT

public static const SYMBOL_DOT: uint

A dot is drawn on the button

SYMBOL_CIRCLE

public static const SYMBOL_CIRCLE: uint

A circle is drawn on the button

private data members

downState

private var downState: BubbleButtonState

Visual state of the button when it is pressed down

overState

private var overState: BubbleButtonState

Visual state of the button when the mouse hovers over it

upState

private var upState: BubbleButtonState

Visual state of the button when it is unselected

lastState

private var lastState: DisplayObject

Last active visual state of the button

callback

private var callback: Function

Function called when the button is clicked

Constructor

BubbleButton

public function BubbleButton(owner: String,  
clickHandler: Function = null,
color: uint = Color.White,
symbol: uint = SYMBOL_NONE,
size: uint = DEFAULT_SIZE)

Creates a button drawn as a bubble.  Drawn with simulated highlight and shadow.

Parameters

ownername of registered owner; see WidgetSprite.register
clickHandlerMouseEvent handler function called when the button is clicked
coloris the base color of the button - assumed to be in the Color class palette
symbolgraphic imprinted on the button (default is SYMBOL_NONE)
sizebutton diameter in pixels excluding any shadow

Callbacks

clickHandlerfunction onBubbleButtonClick(event:MouseEvent):void

Event Handlers

mouseDownHandler

private function mouseDownHandler(event: MouseEvent):void

Change state when the button is pressed

Parameters event - a mouse event

mouseUpHandler

private function mouseUpHandler(event: MouseEvent):void

Change state when the button is released

Parameters event - a mouse event

mouseOutHandler

private function mouseOutHandler(event: MouseEvent):void

Change state when the mouse is moved away from the button

Parameters event - a mouse event

mouseOverHandler

private function mouseOverHandler(event: MouseEvent):void

Change state when the mouse is over the button

Parameters event - a mouse event

mouseClickHandler

private function mouseClickHandler(event: MouseEvent):void

Button click handler calls back to user supplied handler if present

Parameters event - a mouse event

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.
public static const DEFAULT_SIZE: uint
Default button diameter in pixels
public static const SYMBOL_NONE: uint
No symbol is drawn on the button
public static const SYMBOL_X: uint
An X symbol (close) is drawn on the button
public static const SYMBOL_DOT: uint
A dot is drawn on the button
public static const SYMBOL_CIRCLE: uint
A circle is drawn on the button
private var downState: BubbleButtonState
Visual state of the button when it is pressed down
private var overState: BubbleButtonState
Visual state of the button when the mouse hovers over it
private var upState: BubbleButtonState
Visual state of the button when it is unselected
private var lastState: DisplayObject
Last active visual state of the button
private var callback: Function
Function called when the button is clicked
public function BubbleButton(owner: String,  
clickHandler: Function = null,
color: uint = Color.White,
symbol: uint = SYMBOL_NONE,
size: uint = DEFAULT_SIZE)
Creates a button drawn as a bubble.
private function mouseDownHandler(event: MouseEvent):void
Change state when the button is pressed
private function mouseUpHandler(event: MouseEvent):void
Change state when the button is released
private function mouseOutHandler(event: MouseEvent):void
Change state when the mouse is moved away from the button
private function mouseOverHandler(event: MouseEvent):void
Change state when the mouse is over the button
private function mouseClickHandler(event: MouseEvent):void
Button click handler calls back to user supplied handler if present
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
A button widget with a slightly raised look and an optional graphics shape placed above an optional label text.
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