cannot read property 'setTitleText' of undefined - ccui.Button

331 views Asked by At

I am unable to setTitle Text for ccui.Buttona a widget, its showing cannot read property 'setTitleText' of undefined in Cocos2d-JS

Here's the code

    SolutionGrid.setEmptySolutionBox = function(selChild,rChar) {

    selChild.active = true;
    cc.log("get tag of empty solutionBpx" + selChild.getTag());
    var textButtons = ((ccui.Button)(selChild.getChildByTag(5)));
    //var textButtons = ccui.Button(selChild.getChildren()[0]);
    if(textButtons===null){
        cc.log("get tag of empty solutionBpx NULL");
    }
    ///cc.log("get tag of empty solutionBpx" + textButtons.getTag());
    textButtons.setTitleText("a");

};

where selChild is node on which ccui.Button is added

Here how its added , I am getting the tag of that node but can not find the ccui.Button as its child

solBox.addChild(textButton,5,5); //solBox is CCNode and text button is ccui.Button
1

There are 1 answers

0
musikov On

change

var textButtons = ((ccui.Button)(selChild.getChildByTag(5)));

with

var textButtons = selChild.getChildByTag(5);