Class cc.EventListener

Class Summary
Constructor Attributes Constructor Name and Description
 

The base class of event listener.

Method Summary

Class Detail

cc.EventListener()

The base class of event listener.
If you need custom listener which with different callback, you need to inherit this class.
For instance, you could refer to EventListenerAcceleration, EventListenerKeyboard,
EventListenerTouchOneByOne, EventListenerCustom.

Field Detail

<static> <constant> cc.EventListener.ACCELERATION
The type code of acceleration event listener.
<static> <constant> cc.EventListener.CUSTOM
The type code of custom event listener.
<static> <constant> cc.EventListener.KEYBOARD
The type code of keyboard event listener.
<static> <constant> cc.EventListener.MOUSE
The type code of mouse event listener.
<static> <constant> cc.EventListener.TOUCH_ALL_AT_ONCE
The type code of all at once touch event listener.
<static> <constant> cc.EventListener.TOUCH_ONE_BY_ONE
The type code of one by one touch event listener.
<static> <constant> cc.EventListener.UNKNOWN
The type code of unknown event listener.

Method Detail

  • {boolean} checkAvailable()
    Checks whether the listener is available.
    Returns:
    {boolean}
  • {cc.EventListener} clone()
    Clones the listener, its subclasses have to override this method.
    Returns:
    {cc.EventListener}
  • <static> {cc.EventListener} cc.EventListener.create(argObj)
    Create a EventListener object by json object
    cc.EventListener.create({
          event: cc.EventListener.TOUCH_ONE_BY_ONE,
          swallowTouches: true,
          onTouchBegan: function (touch, event) {
              //do something
              return true;
          }
       });
    Parameters:
    {object} argObj
    a json object
    Returns:
    {cc.EventListener}
  • ctor(type, listenerID, callback)
    Initializes event with type and callback function
    Parameters:
    {number} type
    {string} listenerID
    {function} callback
  • {boolean} isEnabled()
    Checks whether the listener is enabled
    Returns:
    {boolean}
  • retain()
    Currently JavaScript Bindings (JSB), in some cases, needs to use retain and release. This is a bug in JSB, and the ugly workaround is to use retain/release. So, these 2 methods were added to be compatible with JSB. This is a hack, and should be removed once JSB fixes the retain/release bug
  • setEnabled(enabled)
    Enables or disables the listener
    Parameters:
    {boolean} enabled