[]Button 添加事件不执行?
Laya.init(1351, 760, Laya.WebGL);
let Stage = Laya.stage;
let Button = Laya.Button;
let Event = Laya.Event;
let Handler = Laya.Handler;
let rightBtn = new Button();
rightBtn.labelFont = "Microsoft YaHei";
rightBtn.label = 'right';
rightBtn.labelSize = 60;
rightBtn.labelColors = '#fff';
rightBtn.labelStrokeColor ='#FF8502';
rightBtn.labelStroke = 10;
rightBtn.x = 100;
rightBtn.y = 200;
rightBtn.on(Event.CLICK, this, clickHandler);
rightBtn.clickHandler = Handler.create(this, function () {
console.log('click handler');
});
function clickHandler () {
console.log('on click')
}
Stage.addChild(rightBtn);
请问一下,为什么事件不执行啊?
没有找到相关结果
已邀请:
2 个回复
Monica - 知识达人
赞同来自:
Event在其他类中有定义了,你需要换一个名字;比如:let Events = Laya.Event;
你这个按钮无法接收鼠标事件是因为没有对按钮设置宽高,加个宽高即可
ttaccp
赞同来自: