SystemEvent Class
Extends EventTarget
Module: cc
The System event, it currently supports the key events and accelerometer events
Index
Methods
setAccelerometerEnabledwhether enable accelerometer eventsetAccelerometerIntervalset accelerometer interval valueonRegister an callback of a specific event type on the EventTarget.offRemoves the listeners previously registered with the same type, callback, target and or useCapture, if only type is passed as parameter, all listeners registered with that type will be removed.targetOffRemoves all callbacks previously registered with the same target (passed as parameter). This is not for removing all listeners in the current event target, and this is not for removing all listeners the target parameter have registered. It's only for removing all listeners (callback and target couple) registered on the current event target by the target parameter.onceRegister an callback of a specific event type on the EventTarget, the callback will remove itself after the first time it is triggered.dispatchEventDispatches an event into the event flow. The event target is the EventTarget object upon which the dispatchEvent() method is called.emitSend an event to this object directly, this method will not propagate the event to any other objects. The event will be created from the supplied message, you can get the "detail" argument from event.detail.
Details
Methods
setAccelerometerEnabled
whether enable accelerometer event
| meta | description |
|---|---|
| Defined in | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/event/system-event.js:92 |
Parameters
isEnableBoolean
setAccelerometerInterval
set accelerometer interval value
| meta | description |
|---|---|
| Defined in | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/event/system-event.js:102 |
Parameters
intervalNumber
on
Register an callback of a specific event type on the EventTarget.
| meta | description |
|---|---|
| Returns | Function |
| Defined in | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/event/event-target.js:217 |
Parameters
typeString A string representing the event type to listen for.callbackFunction The callback that will be invoked when the event is dispatched.The callback is ignored if it is a duplicate (the callbacks are unique).eventEvent event
targetObject The target (this object) to invoke the callback, can be nulluseCaptureBoolean When set to true, the capture argument prevents callbackfrom being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false, callback will NOT be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked when event's eventPhase attribute value is AT_TARGET.
Examples
node.on(cc.Node.EventType.TOUCH_END, function (event) {
cc.log("this is callback");
}, node);
off
Removes the listeners previously registered with the same type, callback, target and or useCapture, if only type is passed as parameter, all listeners registered with that type will be removed.
| meta | description |
|---|---|
| Defined in | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/event/event-target.js:274 |
Parameters
typeString A string representing the event type being removed.callbackFunction The callback to remove.targetObject The target (this object) to invoke the callback, if it's not given, only callback without target will be removeduseCaptureBoolean Specifies whether the callback being removed was registered as a capturing callback or not.If not specified, useCapture defaults to false. If a callback was registered twice, one with capture and one without, each must be removed separately. Removal of a capturing callback does not affect a non-capturing version of the same listener, and vice versa.
Examples
// register touchEnd eventListener
var touchEnd = node.on(cc.Node.EventType.TOUCH_END, function (event) {
cc.log("this is callback");
}, node);
// remove touch end event listener
node.off(cc.Node.EventType.TOUCH_END, touchEnd, node);
// remove all touch end event listeners
node.off(cc.Node.EventType.TOUCH_END);
targetOff
Removes all callbacks previously registered with the same target (passed as parameter). This is not for removing all listeners in the current event target, and this is not for removing all listeners the target parameter have registered. It's only for removing all listeners (callback and target couple) registered on the current event target by the target parameter.
| meta | description |
|---|---|
| Defined in | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/event/event-target.js:329 |
Parameters
targetObject The target to be searched for all related listeners
once
Register an callback of a specific event type on the EventTarget, the callback will remove itself after the first time it is triggered.
| meta | description |
|---|---|
| Defined in | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/event/event-target.js:351 |
Parameters
typeString A string representing the event type to listen for.callbackFunction The callback that will be invoked when the event is dispatched.The callback is ignored if it is a duplicate (the callbacks are unique).eventEvent event
targetObject The target (this object) to invoke the callback, can be nulluseCaptureBoolean When set to true, the capture argument prevents callbackfrom being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false, callback will NOT be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked when event's eventPhase attribute value is AT_TARGET.
Examples
node.once(cc.Node.EventType.TOUCH_END, function (event) {
cc.log("this is callback");
}, node);
dispatchEvent
Dispatches an event into the event flow. The event target is the EventTarget object upon which the dispatchEvent() method is called.
| meta | description |
|---|---|
| Defined in | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/event/event-target.js:396 |
Parameters
eventEvent The Event object that is dispatched into the event flow
emit
Send an event to this object directly, this method will not propagate the event to any other objects. The event will be created from the supplied message, you can get the "detail" argument from event.detail.
| meta | description |
|---|---|
| Defined in | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/event/event-target.js:410 |
Parameters
messageString the message to senddetailAny whatever argument the message needs