Component.EventHandler Class

Module: cc Parent Module: cc

Component will register a event to target component's handler. And it will trigger the handler when a certain event occurs.

!@zh “EventHandler” 类用来设置场景中的事件回调, 该类允许用户设置回调目标节点,目标组件名,组件方法名, 并可通过 emit 方法调用目标函数。

Examples
// Let's say we have a MainMenu component on newTarget
// file: MainMenu.js
cc.Class({
  extends: cc.Component,
  // sender: the node MainMenu.js belongs to
  // eventType: CustomEventData
  onClick (sender, eventType) {
    cc.log('click');
  }
})
// Create new EventHandler
var eventHandler = new cc.Component.EventHandler();
eventHandler.target = newTarget;
eventHandler.component = "MainMenu";
eventHandler.handler = "onClick";
eventHandler.customEventData = "my data";

Index

Properties
  • target Node the node that contains target callback, such as the node example script belongs to
  • component String name of the component(script) that contains target callback, such as the name 'MainMenu' of script in example
  • handler String Event handler, such as function's name 'onClick' in example
  • customEventData String Custom Event Data, such as 'eventType' in example
Methods

Details

Properties

target

the node that contains target callback, such as the node example script belongs to

meta description
Type Node
Defined in cocos2d/core/components/CCComponentEventHandler.js:61
component

name of the component(script) that contains target callback, such as the name 'MainMenu' of script in example

meta description
Type String
Defined in cocos2d/core/components/CCComponentEventHandler.js:72
handler

Event handler, such as function's name 'onClick' in example

meta description
Type String
Defined in cocos2d/core/components/CCComponentEventHandler.js:92
customEventData

Custom Event Data, such as 'eventType' in example

meta description
Type String
Defined in cocos2d/core/components/CCComponentEventHandler.js:103

Methods

emitEvents
meta description
Defined in cocos2d/core/components/CCComponentEventHandler.js:116
Parameters
emit

Emit event with params

meta description
Defined in cocos2d/core/components/CCComponentEventHandler.js:140
Parameters
Examples
// Call Function
var eventHandler = new cc.Component.EventHandler();
eventHandler.target = newTarget;
eventHandler.component = "MainMenu";
eventHandler.handler = "OnClick"
eventHandler.emit(["param1", "param2", ....]);

results matching ""

    No results matching ""