[Resolved] How to call super override function?


#1

Hi,
I have ovverided onExit() function in my JSB-binding code,
I used CocosBuilder as well,
as below is my code:

var choiceteacherNode;
var ChoiceTeacherScene = function(){

    this.onDidLoadFromCCB = function(){
        choiceteacherNode = this;

        this.rootNode.onExit = function(){
            choiceteacherNode.rootNode._super();//HOW TO CALL SUPER onExit() FUNCTION?
        };
     };
};

I have no idea how to call

this._super();

in onExit() function.

It returned “Object # has no method ‘_super’”.

Can someone teach me?
Thanks!


#2

Hi, Simon

In normal case, if you extend from a Cocos2d class, using cc.Node.extend({...}), you can override a function in the extend object. And when you want to access to the parent function which you overrided, you can just use this._super() call
like this:

cc.Node.extend({ onExit:function () { this._super(); }, ... })

However, in your code, I didn’t seen any extend relationship with cocos2d, for example, normally, your ChoiceTeacherScene class should be extended from a cc.Scene class.


#3

But I didn’t know much about CocosBuilder, maybe they have other logic to make the extend relationship happen, hope someone else can give more help.

Huabin


#4

Huabin LING wrote:

But I didn’t know much about CocosBuilder, maybe they have other logic to make the extend relationship happen, hope someone else can give more help.
>
Huabin
Thank you, Huabin.
Wating for reply.
:frowning:


#5

Hi,Simon Pan.
You can have a try like :

choiceteacherNode.rootNode.prototype.onExit.call(choiceteacherNode.rootNode);

#6

Hi Simon,

There is a way to call super function:

@ this.onDidLoadFromCCB = function(){
choiceteacherNode = this;
var rootNodeonExitSuper = this.rootNode.onExit;
this.rootNode.onExit = function(){
rootNodeonExitSuper.apply(this);
choiceteacherNode.removeTeacherScene();
label_master_array = null;
choiceteacherNode = null;
};
};@

Hopes that helps
David


#7

Thanks Xingsen Ma.

Thanks, Dingping,
You always teach me on first time.

I found another solution as well:
just write this line to this.onExit() function:

cc.Node.prototype.onExit.call(this);

This is equal to

this._super();

This is last code and it works:

var choiceteacherNode;
var ChoiceTeacherScene = function(){

    this.onDidLoadFromCCB = function(){
        choiceteacherNode = this;

        this.rootNode.onExit = function(){
            cc.Node.prototype.onExit.call(this);//Call parent's onExit() function to avoid some stuff doesn't release completely when remove child choiceteacherNode.
        };
     };
};