1

当我推送一个尝试更改场景的菜单项时,我从 Chrome 控制台收到此错误消息:

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)

这是我的菜单代码:

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);

以及 menuitem1 的功能:

onPlay:function(){
    //cc.log("==onplay clicked");
    //var director = cc.Director.getInstance();
    //director.replaceScene(new MainLayer());
}
4

1 回答 1

0

你只需要交换thisthis.onPlay

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

Create函数如下所示:

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

于 2014-07-23T20:16:04.790 回答