SelectableButton
| Kind of class: | class |
|---|---|
| Inherits from: | DelayButton < EventButton < EventMovieClip < MovieClip |
| Author: | Arthur Clemens |
| Classpath: | org.asapframework.ui.buttons.SelectableButton |
| File last modified: | Sunday, 08 October 2006, 10:27:50 |
Convenience class to create buttons with a "selected" state, for instance to be used in menus.
SelectableButton takes care of state management like event handling and the specific bahavior of the selected button. Subclasses only need to take care of drawing each button state: up, over and selected.
SelectableButton offers cascading functionality from superclasses:
SelectableButton takes care of state management like event handling and the specific bahavior of the selected button. Subclasses only need to take care of drawing each button state: up, over and selected.
SelectableButton offers cascading functionality from superclasses:
- Control timing with indelay, outdelay and afterdelay from DelayButton
- Use setSendEventOnRoll and setSendEventOnPress to control dispatching of events (EventButton)
Usage:
- An example for a SelectableButton subclass, MenuButton:
import org.asapframework.ui.buttons.SelectableButton; class MenuButton extends org.asapframework.ui.buttons.SelectableButton { private function drawUpState () : Void { gotoAndStop("up"); } private function drawOverState () : Void { gotoAndStop("over"); } private function drawSelectedState () : Void { gotoAndStop("selected"); } }
An example for a "next" button subclass that shows an disabled state:class NextButton extends SelectableButton { public function NextButton () { super(); setSendEventOnPress(true); // let the button send events on onPress } private function drawUpState () : Void { gotoAndStop("up"); } private function drawOverState () : Void { gotoAndStop("over"); } private function drawDisabledState () : Void { gotoAndStop("disabled"); } private function drawEnabledState () : Void { gotoAndStop("up"); } }
Summary
Constructor
Instance properties
Instance properties inherited from DelayButton
Instance properties inherited from EventButton
Instance properties inherited from EventMovieClip
Instance methods
- doRollOver
- doRollOut
- doRelease
- doPress
- select : Void
- Sets the button state to selected.
- deselect : Void
- Sets the button state to deselected.
- setEnabled (inState:Boolean) : Void
- Sets the button to enabled of disabled.
- toString : String
- setId (inId:String) : Void
- Sets the state id.
- getId : String
- Gets the state id.
- init : Void
- Initializes button properties; to be implemented by subclasses.
- update : Void
- Updates the visual state.
- updateSelectedState : Void
- Visually updates to selected state.
- updateEnabledState : Void
- Visually updates to enabled state.
- drawUpState : Void
- Subclasses implement visual behavior at "up" state.
- drawOverState : Void
- Subclasses implement visual behavior at "over" state.
- drawSelectedState : Void
- Subclasses implement visual behavior at "selected" state.
- drawDeselectedState : Void
- Subclasses implement visual behavior at "selected" state.
- drawDisabledState : Void
- Subclasses implement visual behavior at "disabled" state.
- drawEnabledState : Void
- Subclasses implement visual behavior at "enabled" state.
Instance methods inherited from DelayButton
Instance methods inherited from EventButton
Event handlers
Event handlers inherited from DelayButton
Event handlers inherited from EventButton
Constructor
SelectableButton
function SelectableButton (
)
Creates a new SelectableButton. Calls init to initialize variables.
Instance properties
mEnabled
private mEnabled:Boolean = true
(read)
mId
private mId:String
(read)
The state id. If a stage manager is used, the button is passed the unique state id to fetch the correct state when the button is clicked.
mSelected
private mSelected:Boolean = false
(read)
The selected state. Usually this means the button will be highlighted and not clickable.
Instance methods
deselect
function deselect (
) : Void
Sets the button state to deselected.
drawDeselectedState
private function drawDeselectedState (
) : Void
Subclasses implement visual behavior at "selected" state. Default: drawUpState().
drawDisabledState
private function drawDisabledState (
) : Void
Subclasses implement visual behavior at "disabled" state.
drawEnabledState
private function drawEnabledState (
) : Void
Subclasses implement visual behavior at "enabled" state.
drawOverState
private function drawOverState (
) : Void
Subclasses implement visual behavior at "over" state.
drawSelectedState
private function drawSelectedState (
) : Void
Subclasses implement visual behavior at "selected" state.
drawUpState
private function drawUpState (
) : Void
Subclasses implement visual behavior at "up" state.
getId
function getId (
) : String
Gets the state id.
Returns:
- The id.
init
private function init (
) : Void
Initializes button properties; to be implemented by subclasses. For example, DelayButton timing properties can be set here.
Example:
-
private function init () : Void { setSendEventOnPress(true); // let the button send events on onPress indelay = .15; // DelayButton property: when rolled over, onRollOver is called after .15 seconds }
select
function select (
) : Void
Sets the button state to selected.
setEnabled
function setEnabled (
inState:Boolean) : Void
Sets the button to enabled of disabled. Use this method; do not call
.enabled on the button directly. Parameters:
inState:
true sets state to enabled; false to disabled
setId
function setId (
inId:String) : Void
Sets the state id.
Parameters:
inId:
the id
update
private function update (
) : Void
Updates the visual state. Calls updateSelectedState and updateEnabledState.
updateEnabledState
private function updateEnabledState (
) : Void
Visually updates to enabled state.
updateSelectedState
private function updateSelectedState (
) : Void
Visually updates to selected state.
Implementation note: