Issue with mouse events

Hi folks! Im just discovering cocos2d with JavaScript and I want to play a little with mouse events. There’s my code:

var HelloWorldLayer = cc.LayerColor.extend({
    sprite:null,
   ctor:function () {
        this._super();
        this.init();
    },
    init:function () {
        this._super();
        var winsize = cc.director.getWinSize();

        var centerPos = cc.p(320, 240);
        var spriteBG = cc.Sprite.create(res.Bg_png);
        spriteBG.setPosition(centerPos);
        this.addChild(spriteBG); 

        var centerPos = cc.p(320, 100);
        var spriteBG = cc.Sprite.create(res.Globo_png);
        spriteBG.setPosition(centerPos);
        this.addChild(spriteBG,1); 
    },
    onMouseDown: function(event) {
        alert('ok');
    }
});

var HelloWorldScene = cc.Scene.extend({
    onEnter:function () {
        this._super();
        var layer = new HelloWorldLayer();
        this.addChild(layer);
    }
});

MouseDown don’t work and if I add ( this.setMouseEnabled(true):wink: I got and error…

anybody can help me?
thanks!

adding this.setMouseEnabled(true); works like a charm in 2.2.3.

init:function () {
        this._super();
        this.setMouseEnabled(true);

Please post your engine version and the error.

Which version are you using ? Cocos2d-JS 3.0 or 2.x?

Hi! Im using Cocos2d-JS 3.0

As iQD said, your code is for v2.x. You should take a look at this document: http://www.cocos2d-x.org/docs/manual/framework/html5/v3/eventManager/en