Class cc.MenuItemToggle

Class Summary
Constructor Attributes Constructor Name and Description
 
A simple container class that "toggles" it's inner items
The inner items can be any MenuItem

Method Summary

Class Detail

cc.MenuItemToggle()
A simple container class that "toggles" it's inner items
The inner items can be any MenuItem
// Example
//create a toggle item with 2 menu items (which you can then toggle between them later)
var toggler = new cc.MenuItemToggle( new cc.MenuItemFont("On"), new cc.MenuItemFont("Off"), this.callback, this)
//Note: the first param is the target, the second is the callback function, afterwards, you can pass in any number of menuitems

//if you pass only 1 variable, then it must be a cc.MenuItem
var notYetToggler = new cc.MenuItemToggle(cc.MenuItemFont("On"));//it is useless right now, until you add more stuff to it
notYetToggler.addSubItem(new cc.MenuItemFont("Off"));
//this is useful for constructing a toggler without a callback function (you wish to control the behavior from somewhere else)

Field Detail

{Number} selectedIndex
- Index of selected sub item
{Array} subItems
- Sub items

Method Detail

  • activate()
    activate the menu item
  • addSubItem(item)
    add the subitem for cc.MenuItemToggle
    Parameters:
    {cc.MenuItem} item
  • <static> {cc.MenuItemToggle} cc.MenuItemToggle.create()
    create a simple container class that "toggles" it's inner items
    The inner items can be any MenuItem
    Deprecated:
    since v3.0 please use new cc.MenuItemToggle(params) instead
    Returns:
    {cc.MenuItemToggle}
  • ctor()
    Constructor of cc.MenuItemToggle
  • {cc.Color} getColor()
    return the color of cc.MenuItemToggle
    Returns:
    {cc.Color}
  • {Number} getOpacity()
    return the opacity of cc.MenuItemToggle
    Returns:
    {Number}
  • {Number} getSelectedIndex()
    return the index of selected
    Returns:
    {Number}
  • {cc.MenuItem} getSelectedItem()
    returns the selected item.
    Returns:
    {cc.MenuItem}
  • {Array} getSubItems()
    similar to get children,return the sumItem array.
    Returns:
    {Array}
  • {Boolean} initWithItems(array, secondTolast, last)
    initializes a cc.MenuItemToggle with items
    Parameters:
    {...cc.MenuItem} array
    the rest in the array are cc.MenuItems
    {function|String} secondTolast
    the second item in the args array is the callback
    {cc.Node} last
    the first item in the args array is a target
    Returns:
    {Boolean}
  • onEnter()
    *

    Event callback that is invoked every time when cc.MenuItemToggle enters the 'stage'.
    If the cc.MenuItemToggle enters the 'stage' with a transition, this event is called when the transition starts.
    During onEnter you can't access a "sister/brother" node.
    If you override onEnter, you must call its parent's onEnter function with this._super().

  • selected()
    menu item is selected (runs callback)
  • {cc.MenuItem} selectedItem()
    returns the selected item (deprecated in -x, please use getSelectedItem instead.)
    Returns:
    {cc.MenuItem}
  • setColor(Color)
    set the color for cc.MenuItemToggle
    Parameters:
    {cc.Color} Color
  • setEnabled(enabled)
    set the enable status for cc.MenuItemToggle
    Parameters:
    {Boolean} enabled
  • setOpacity(opacity)
    set the opacity for cc.MenuItemToggle
    Parameters:
    {Number} opacity
  • setSelectedIndex(SelectedIndex)
    set the seleceted index for cc.MenuItemToggle
    Parameters:
    {Number} SelectedIndex
  • setSubItems(subItems)
    set the subitem for cc.MenuItemToggle
    Parameters:
    {cc.MenuItem} subItems
  • unselected()
    menu item goes back to unselected state