Extend MenuItemSprite in JSB


#1

Can someone tell me the proper way to extend a MenuItemSprite in JSB that will work with iOS? I’m need to override the selected and unselected functions within the MenuItemSprite class. Any help would be appreciated.


#2

You need to add cc.MenuItemSprite.extend = cc.Class.extend into the file: jsb_cocos2d.js

Jon Jones wrote:

Can someone tell me the proper way to extend a MenuItemSprite in JSB that will work with iOS? I’m need to override the selected and unselected functions within the MenuItemSprite class. Any help would be appreciated.


#3

Thanks, but I’ve done that. Here is the simplest version of what I’m trying to do:

var MyMenuItemSprite = cc.MenuItemSprite.extend({

ctor:function(normal, pressed, released, target) {
this.*super;
this.initWithNormalSprite,
cc.Sprite.create, cc.Sprite.create,
this.clicked, this);
},
selected:function {
this.*super();
},

unselected:function() {
this._super();
},

clicked:function() {
// do nothing
}
});

This works in HTML5. In iOS, it gets an error on the initWithNormalSprite. Here is the error:

Assertion failure: !cx->isExceptionPending(), at …/jscntxtinlines.h:376

Justin Zhang wrote:

You need to add cc.MenuItemSprite.extend = cc.Class.extend into the file: jsb_cocos2d.js
>
Jon Jones wrote:
> Can someone tell me the proper way to extend a MenuItemSprite in JSB that will work with iOS? I’m need to override the selected and unselected functions within the MenuItemSprite class. Any help would be appreciated.


#4

Yea, the method :initWithNormalSprite have not bound also, If you want to do like this, may be you need bound by yourself.

Jon Jones wrote:

Thanks, but I’ve done that. Here is the simplest version of what I’m trying to do:
>
var MyMenuItemSprite = cc.MenuItemSprite.extend({
>
ctor:function(normal, pressed, released, target) {
this.*super;
>
this.initWithNormalSprite,
cc.Sprite.create, cc.Sprite.create,
this.clicked, this);
},
>
selected:function {
this.*super();
},
>
unselected:function() {
this._super();
},
>
clicked:function() {
// do nothing
}
});
>
This works in HTML5. In iOS, it gets an error on the initWithNormalSprite. Here is the error:
>
Assertion failure: !cx->isExceptionPending(), at …/jscntxtinlines.h:376
>
>
Justin Zhang wrote:
> You need to add cc.MenuItemSprite.extend = cc.Class.extend into the file: jsb_cocos2d.js
>
> Jon Jones wrote:
> > Can someone tell me the proper way to extend a MenuItemSprite in JSB that will work with iOS? I’m need to override the selected and unselected functions within the MenuItemSprite class. Any help would be appreciated.


#5

Any other way of doing it? I don’t know what “bound by yourself” means.

Justin Zhang wrote:

Yea, the method :initWithNormalSprite have not bound also, If you want to do like this, may be you need bound by yourself.
>
>
Jon Jones wrote:
> Thanks, but I’ve done that. Here is the simplest version of what I’m trying to do:
>
> var MyMenuItemSprite = cc.MenuItemSprite.extend({
>
> ctor:function(normal, pressed, released, target) {
> this.*super;
>
> this.initWithNormalSprite,
> cc.Sprite.create, cc.Sprite.create,
> this.clicked, this);
> },
>
> selected:function {
> this.*super();
> },
>
> unselected:function() {
> this._super();
> },
>
> clicked:function() {
> // do nothing
> }
> });
>
> This works in HTML5. In iOS, it gets an error on the initWithNormalSprite. Here is the error:
>
> Assertion failure: !cx->isExceptionPending(), at …/jscntxtinlines.h:376
>
>
> Justin Zhang wrote:
> > You need to add cc.MenuItemSprite.extend = cc.Class.extend into the file: jsb_cocos2d.js
> >
> > Jon Jones wrote:
> > > Can someone tell me the proper way to extend a MenuItemSprite in JSB that will work with iOS? I’m need to override the selected and unselected functions within the MenuItemSprite class. Any help would be appreciated.


#6

Looking at jsb_cocos2d_manual.mm there seems to be only a “init” method for javascript (which doesn’t seem to match the documentation) but if I try calling init I get a “Invalid Proxy object” error.

Jon Jones wrote:

Any other way of doing it? I don’t know what “bound by yourself” means.
>
Justin Zhang wrote:
> Yea, the method :initWithNormalSprite have not bound also, If you want to do like this, may be you need bound by yourself.
>
>
> Jon Jones wrote:
> > Thanks, but I’ve done that. Here is the simplest version of what I’m trying to do:
> >
> > var MyMenuItemSprite = cc.MenuItemSprite.extend({
> >
> > ctor:function(normal, pressed, released, target) {
> > this.*super;
> >
> > this.initWithNormalSprite,
> > cc.Sprite.create, cc.Sprite.create,
> > this.clicked, this);
> > },
> >
> > selected:function {
> > this.*super();
> > },
> >
> > unselected:function() {
> > this._super();
> > },
> >
> > clicked:function() {
> > // do nothing
> > }
> > });
> >
> > This works in HTML5. In iOS, it gets an error on the initWithNormalSprite. Here is the error:
> >
> > Assertion failure: !cx->isExceptionPending(), at …/jscntxtinlines.h:376
> >
> >
> > Justin Zhang wrote:
> > > You need to add cc.MenuItemSprite.extend = cc.Class.extend into the file: jsb_cocos2d.js
> > >
> > > Jon Jones wrote:
> > > > Can someone tell me the proper way to extend a MenuItemSprite in JSB that will work with iOS? I’m need to override the selected and unselected functions within the MenuItemSprite class. Any help would be appreciated.


#7

did you fix it??

it make me… crz;; T_T