Multiple Buttons Same Function

I have created more than one Button all having the same function, But the problem i could not identify which one was pressed. :frowning:

Please advice

hideho

if you add an event parameter to the function you call, you can access the individual buttons nodes and, for example, the buttons labels string:

testEvent:function(event){
        var btnLblStr=event.target.getChildByName("Label").getComponent(cc.Label).string;  
},

cheers

1 Like

Thanks very much it worked :grinning::grinning:

Hi @malbishtawi,

if I may recommend, there is a more elegant solution. The cc.Button click event has a CustomEventData property:

And you get the value as a function parameter:

onTapButton: function (event, customEventData, active) { 
    // Your code here to handle customEventData...
}

I hope this helps as well.

Best regards,
Zsolt

1 Like

Thanks @PZsolt27 … i will try it as well … :slight_smile:
i am still new to the environment and would like to know the best ways to accomplish my tasks …

Thanks