BasicButtonMenu

Kind of class: public class
Package:
Inherits from:
  • Sprite
Known subclasses:
Version: 08 Apr 2010 Fixed issue with button spacing
05 Apr 2010
Author: John Polacek, john@johnpolacek.com
Classpath: com.johnpolacek.ui.BasicButtonMenu
File last modified: Wednesday, 16 February 2011, 18:35:25
The BasicButtonMenu class is for creating simple button menu navigation.
Example

  • Create a BasicButtonMenu with 5 buttons:
    var menu:BasicButtonMenu = new BasicButtonMenu();
    for (i = 0; i < 5; i++)
    {
    var menuButton:Sprite = new Sprite();
       var menuButtonText:TextField = new TextField();
       menuButtonText.text = "Button #"+(i+1);
       menuButton.addChild(menuButtonText);
       menu.addButton(menuButton);
    };
    menu.addEventListener(UIEvent.BUTTON_SELECT, onButtonSelect);
    function onButtonSelect(event:UIEvent):void
    {
    trace("Menu Button Index: "+event.value); 
    }
    

Summary

Constructor
Instance properties
  • buttons : Array
    • Array of buttons in the menu.
  • buttonAlpha : Number
    • Base alpha of buttons in the menu.
  • rolloverAlpha : Number
    • Rollover alpha of buttons in the menu.
  • rolloverColor : String
    • Rollover color of buttons in the menu.
  • selectColor : String
    • Select color of buttons in the menu.
  • spacing : int
    • Sets the spacing in pixels between buttons.
  • isVertical : Boolean
    • Sets alignment.
  • currButtonIndex : int
    • Index of current button selected
  • bubbles : Boolean
    • Determines if button select event bubbles
  • background : Sprite
    • Optional background shape
  • showButtonSelection : Boolean
    • If true, selected button maintains its rollover state when selected
  • buttonSelectGraphic : Sprite
    • Optional graphic that appears next to selected menu button
Instance methods
  • addButton (sprite:Sprite, val:String = "", ba:Number = -1) : void
  • addButtonSelectGraphic (graphic:Sprite, graphicX:int, graphicY:int, transitionIn:Function = null) : void
  • hideButtons () : void
  • showButton (i:int) : void
  • updateGraphic () : void
  • onClick (event:MouseEvent) : void
    • Button onClick handler
  • selectButton (buttonIndex:int) : void
    • Selects the active button for the menu, as if clicked, but does not trigger event)
  • addBackground (backgroundColor:uint, backgroundAlpha:Number, margin:int = 20) : void

Constructor

BasicButtonMenu

function BasicButtonMenu(ba:Number = .9)
Parameters
ba:Alpha of button when not selected. Default .9

Instance properties

background

background:Sprite(read,write)

Optional background shape

bubbles

bubbles:Boolean = true(read,write)

Determines if button select event bubbles

buttonAlpha

buttonAlpha:Number = .9(read,write)

Base alpha of buttons in the menu.

buttonSelectGraphic

buttonSelectGraphic:Sprite(read,write)

Optional graphic that appears next to selected menu button

buttons

buttons:Array = [](read,write)

Array of buttons in the menu.

currButtonIndex

currButtonIndex:int = -1(read,write)

Index of current button selected

isVertical

isVertical:Boolean = true(read,write)

Sets alignment. If true, buttons are stacked vertically.

rolloverAlpha

rolloverAlpha:Number = 1(read,write)

Rollover alpha of buttons in the menu. Default .9

rolloverColor

rolloverColor:String(read,write)

Rollover color of buttons in the menu. Default null (none)

selectColor

selectColor:String(read,write)

Select color of buttons in the menu. Default null (none)

showButtonSelection

showButtonSelection:Boolean = true(read,write)

If true, selected button maintains its rollover state when selected

spacing

spacing:int(read,write)

Sets the spacing in pixels between buttons. Default 1

Instance methods

addBackground

function addBackground(backgroundColor:uint, backgroundAlpha:Number, margin:int = 20) : void

addButton

function addButton(sprite:Sprite, val:String = "", ba:Number = -1) : void
Parameters
 

addButtonSelectGraphic

function addButtonSelectGraphic(graphic:Sprite, graphicX:int, graphicY:int, transitionIn:Function = null) : void

hideButtons

function hideButtons() : void

onClick

function onClick(event:MouseEvent) : void

Button onClick handler

selectButton

function selectButton(buttonIndex:int) : void

Selects the active button for the menu, as if clicked, but does not trigger event)

showButton

function showButton(i:int) : void

updateGraphic

function updateGraphic() : void