MenuItem callback

hello forum.

I’m new in cocos html5.

i’m trying some samples and don’t know why my MenuItemSprite doesn’t run callback function.

this is my code, can u help me?

var primeraEscena = cc.Scene.extend({
onEnter:function(){
this.*super;
var layer = new Escenas;
layer.init;
this.addChild;
}
})
var Escenas = cc.Layer.extend
{
this.*super();
try{
this._menuItem = new myMenuItem();
var s = cc.Director.getInstance().getWinSize();

var layer1 = cc.LayerColor.create(new cc.Color4B(255, 255, 255, 255), 600, 600);
layer1.setAnchorPoint(new cc.Point(0.5,0.5));
var escena1Label = cc.LabelTTF.create(“Escena1”, “Arial”, 12);
escena1Label.setPosition(new cc.Point(s.width/2,s.height/2+80));
escena1Label.setColor(new cc.Color3B(0,0,0));
escena1Label.schedule(function()
{
});
layer1.addChild(escena1Label);
this.addChild(layer1);

//this.addChild(boton)
//boton.setTouchEnabled(true)
//var menu = cc.Menu.create(boton);
// var label = cc.LabelTTF.create(“ey”, “Arial”, 14);
// var back = cc.MenuItemLabel.create(label);

var botonImg = cc.Sprite.create(“img/greencircle.png”, cc.rect(0, 0, 40, 40));
var botonImg2 = cc.Sprite.create(“img/greencircle.png”, cc.rect(1, 0, 40, 40));
var botonImg3 = cc.Sprite.create(“img/greencircle.png”, cc.rect(2, 0, 40, 40));
var boton = cc.MenuItemSprite.create(botonImg, botonImg2,botonImg3, this.func, this);
var menu = cc.Menu.create(boton);
menu.alignItemsVerticallyWithPadding(10);
this.addChild(menu);
}catch(e){alert(e)}

return true;
},
func:function(sPender){
alert(“Wiiii”)
},
onBackCallback:function (pSender) {
alert(“menuLabel”)
// var scene = cc.Scene.create();
// scene.addChild(SysMenu.create());
// cc.Director.getInstance().replaceScene(cc.TransitionFade.create(1.2, scene));
}

});

function funcion(){
alert(“por funcion”)
}

Hi Angel Gonzalez,

What is the error message of MenuItemSprite?
Can you see the “boton” on the screen?

Hi.

there’s no error message, but yes, i can see the “boton” menuItemSprite on the screen.

Se me ocurren 2 cosas (aunque no creo que sea ninguna de las 2 el problema en realidad):

  1. Probá con pasarle sólo 2 imágenes al botón:
    var boton = cc.MenuItemSprite.create(botonImg, botonImg2, this.func, this);

  2. Probá agregar un “;” al final del alert:
    alert("Wiiii");

Dicho sea de paso, la forma en que estás haciendo algunas cosas me resulta algo extraña, acá tenés un tutorial en español por si te hace falta:


I can think of 2 things (even thought I don’t think it should be neither of them):

  1. Try passing only 2 images to the sprite creation method:
    var boton = cc.MenuItemSprite.create(botonImg, botonImg2, this.func, this);

  2. Try adding a “;” at the end of the alert:
    alert("Wiiii");

I dont know what error occured when using cc.MenuItemSprite.create(botonImg, botonImg2, this.func, this);
however cc.MenuItemSprite.create(normalImage, SelectedImage, disabledImage, targetNode.callback, targetNode)
this interface works well.