在官网下载了cocos,新建了一工程,用cocos studio在场景中拖了一个label和一个button
目标是点击button改变label的内容,但是不起作用
app.js的代码如下:
var HelloWorldLayer = cc.Layer.extend({
mainscene: null,
ctor: function () {
this._super();
var size = cc.winSize;
mainscene = ccs.load(res.MainScene_json).node;
this.addChild(mainscene);
this.dealWidgets();
return true;
},
testFunction: function () {
return "aaa";
},
dealWidgets: function () {
var btnCount = ccui.helper.seekWidgetByName(mainscene, "Button_1");
btnCount.addClickEventListener(this.btnClickEvent);
},
btnClickEvent: function (sender, type) {
var text = ccui.helper.seekWidgetByName(mainscene, "Text_1");
text.string = this.testFunction();
},
});
var HelloWorldScene = cc.Scene.extend({
onEnter: function () {
this._super();
var layer = new HelloWorldLayer();
this.addChild(layer);
}
});