Options
All
  • Public
  • Public/Protected
  • All
Menu

Class EventHandler

The EventHandle class sets the event callback in the scene. This class allows the user to set the callback target node,target component name,component method name, and call the target method through the emit method.

example
import { Component } from 'cc';
const eventHandler = new Component.EventHandler();
eventHandler.target = newTarget;
eventHandler.component = "MainMenu";
eventHandler.handler = "OnClick";
eventHandler.customEventData = "my data";

Hierarchy

  • EventHandler

Index

Properties

_componentId

_componentId: string = ""

component

component: string = ""

Target component name.

customEventData

customEventData: string = ""

Custom event data.

handler

handler: string = ""

Response event function name.

target

target: Node | null = null

Target node.

Accessors

componentName

  • get componentName(): any
  • set componentName(value: any): void

Methods

Private compId2Name

  • compId2Name(compId: any): any

Private compName2Id

  • compName2Id(compName: any): any

Private genCompIdIfNeeded

  • _genCompIdIfNeeded(): void

emit

  • emit(params: any[]): void
  • Trigger the target callback with given arguments

    example
    import { Component } from 'cc';
    const eventHandler = new Component.EventHandler();
    eventHandler.target = newTarget;
    eventHandler.component = "MainMenu";
    eventHandler.handler = "OnClick"
    eventHandler.emit(["param1", "param2", ....]);

    Parameters

    • params: any[]

      The arguments for invoking the callback

    Returns void

Static emitEvents

Generated using TypeDoc