其他分享
首页 > 其他分享> > CocosCreator 代码添加点击事件函数

CocosCreator 代码添加点击事件函数

作者:互联网

const {ccclass, property} = cc._decorator;

@ccclass
export default class TestButton extends cc.Component{
	
	private _button:cc.Button=null;
	
	protected onl oad():void{
		super.onLoad();
		this._button=this.getComponent(cc.Button);
		
		var eventHandler=new cc.Component.EventHandler();
		eventHandler.target=this.node;
		eventHandler.component="TestButton";
		eventHandler.handler="onClick";
		eventHandler.customEventData="my data";
		
		this._button.clickEvents.push(eventHandler);
		
	}
	
	private onClick(event:cc.Event.EventTouch,customData:any):void{
		
	}
	
}

标签:eventHandler,cc,button,private,CocosCreator,点击,添加,._,void
来源: https://www.cnblogs.com/kingBook/p/12956437.html