1

I'm getting this error message from Chrome Console, when I push a Menu item that tries to change the scene:

Uncaught TypeError: object is not a function CCMenuItem.js:174
cc.MenuItem.cc.Node.extend.activate CCMenuItem.js:174
cc.MenuItemLabel.cc.MenuItem.extend.activate CCMenuItem.js:333
(anonymous function) CCClass.js:138
cc.Menu.cc.Layer.extend.onTouchEnded CCMenu.js:442
cc.TouchDispatcher.cc.Class.extend.touches CCTouchDispatcher.js:376
cc.TouchDispatcher.cc.Class.extend.touchesEnded CCTouchDispatcher.js:508
cc.ProcessMouseupEvent CCTouchDispatcher.js:630
(anonymous function)

this is my code from the menu:

var menuItem1 = new cc.MenuItemFont.create("Play",this,this.onPlay);
var size = cc.Director.getInstance().getWinSize();
menuItem1.setPosition(new cc.Point(size.width/2,size.height/2+50));

var menu = cc.Menu.create(menuItem1);

menu.setPosition(new cc.Point(0,0));

this.addChild(menu);

And the function of menuitem1:

onPlay:function(){
    //cc.log("==onplay clicked");
    //var director = cc.Director.getInstance();
    //director.replaceScene(new MainLayer());
}
CodeSmile
  • 64,284
  • 20
  • 132
  • 217
user3511563
  • 397
  • 2
  • 5
  • 18
  • 1
    This is cocos2d-js, right? If so please don't use cocos2d-iphone tag as that is a different engine. – CodeSmile Apr 14 '14 at 06:16
  • Cocos2d-html and -js tags has almost no followers – user3511563 Apr 14 '14 at 19:28
  • 2
    That's because they're less popular. You probably won't get help from users of more popular but unrelated tags. If SO worked that way, we'd all tag most questions with 'programming'. ;) – CodeSmile Apr 14 '14 at 21:19

1 Answers1

0

You just need to swap this and this.onPlay:

var menuItem1 = new cc.MenuItemFont.create("Play",this.onPlay,this);

Create function looks like this:

cc.MenuItemFont.create = function (value, callback, target) { return new cc.MenuItemFont(value, callback, target); };

musikov
  • 640
  • 1
  • 4
  • 13