[FIXED] TypeError: callback.bind is not a function on MenuItemImage

Hi

I was creating a Menu with MenuItemImage , and every thing was fine with web testing…

but when I tested my project on win32 or Android , this error is shown :

......~PrebuiltRuntimeJs/debugruntime/script/jsb_create_apis.js:243:TypeError: callback.bind is not a function

with a fast look at the source code of the MenuItemImage , I found the mistake I made.

it was not documented clearly , but an example was written at MenuItemSprite which helped me very much.

what I was doing :

var numberItem = new cc.MenuItemImage(normalNumber, selectedNumber, disabledNumber, this.onNumberTouch);

I add the 3 states of the button , and the callback function.
this is ok with web version , but on Native Platforms you need to add the “target
so the code will be :

var numberItem = new cc.MenuItemImage(normalNumber, selectedNumber, disabledNumber, this.onNumberTouch,this);

that is it …

and it is pretty strange for me because when I add only two states of the MenuItem , no errors occurs when I ignore the “target” , like this :

var noItem = new cc.MenuItemImage(normalNo,selectedNo,  this.onNoTouch);

I hope I understand this .

1 Like

Thanks, it’s a bug when creating MenuItemImage in JSB.

I just added a pull request to fix it:

https://github.com/cocos2d/cocos2d-js/pull/1526

1 Like