Here is my code:
In scene 1 with a button that sends me to scene 2, and a node with the following code. The node is placed at the root of scene.
cc.Class({
extends: cc.Component,
onLoad () {
cc.game.addPersistRootNode(this.node);
},
start () {
cc.log('toolbox start');
},
saySomething : function(){
cc.log('say what');
}
});
In scene 2, a node with this code, this node is put in root of scene.
cc.Class({
extends: cc.Component,
start () {
var toolbox = cc.find("Toolbox");
this.scheduleOnce(function() {
this.ToolBoxFound();
}, 2);
},
ToolBoxFound : function(){
cc.log('Find tool box');
this.toolbox.getComponent(cc.Node).getComponent('Toolbox').saySomething();
}
});
I’m getting this error:
Uncaught TypeError: Cannot read property ‘getComponent’ of undefined