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

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
    {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
    since v3.0 please use new cc.MenuItemToggle(params) instead
  • ctor()
    Constructor of cc.MenuItemToggle
  • {cc.Color} getColor()
    return the color of cc.MenuItemToggle
  • {Number} getOpacity()
    return the opacity of cc.MenuItemToggle
  • {Number} getSelectedIndex()
    return the index of selected
  • {cc.MenuItem} getSelectedItem()
    returns the selected item.
  • {Array} getSubItems()
    similar to get children,return the sumItem array.
  • {Boolean} initWithItems(args[last-1], args[last])
    initializes a cc.MenuItemToggle with items
    {cc.MenuItem} args[0...last-2]
    the rest in the array are cc.MenuItems
    {function|String} args[last-1]
    the second item in the args array is the callback
    {cc.Node} args[last]
    the first item in the args array is a target
  • 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.)
  • setColor(Color)
    set the color for cc.MenuItemToggle
    {cc.Color} Color
  • setEnabled(enabled)
    set the enable status for cc.MenuItemToggle
    {Boolean} enabled
  • setOpacity(opacity)
    set the opacity for cc.MenuItemToggle
    {Number} opacity
  • setSelectedIndex(SelectedIndex)
    set the seleceted index for cc.MenuItemToggle
    {Number} SelectedIndex
  • setSubItems(subItems)
    set the subitem for cc.MenuItemToggle
    {cc.MenuItem} subItems
  • unselected()
    menu item goes back to unselected state