Hi, I am using CocosStudio v3.10 and have a button in the scene file. I am trying to get access to the button in code so as to attach a listener to it. So far, the button is returning null. Does anyone see what I am doing wrong? Thanks
var CocosTestLayer = cc.Layer.extend({
sprite:null,
ctor:function () {
this._super();
var size = cc.winSize;
var mainscene = ccs.load(res.MainScene_json);
this.addChild(mainscene.node);
fireButton = mainscene.node.getChildByName("Button_Fire");
cc.log(fireButton.x);
return true;
},
update: function (dt) {
FrameUpdate(dt, this);
}
I used getChildByTag and was no longer getting a null object, but was not getting the correct object. I looked into the scene and there were two buttons with the same tag. I manually changed one of the tags to an unused value and was able to grab the correct object. I then switched uncommented the getChildByName call and it too is now working. Thanks for your assistance.