kingBook

导航

CocosCreator 代码添加点击事件函数

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

posted on 2020-05-25 13:42  kingBook  阅读(1756)  评论(0编辑  收藏  举报