Ahh that makes sense now!
var myApp = new cocos2dApp(MainLayer.sceneWithSelf);
As your main.js is currently set up, the cocos2dApp expects a scene’s constructor function to invoke after it has loaded all of the resources. When you give it the ’()’s then you’re invoking your function which is trying to create the scene and layer before such important things like the Director being set up is complete.
You can change main.js to better fit the scheme you’ve created.
Change the above line to the one below:
var myApp = new cocos2dApp(MainLayer);
And change the line:
director.replaceScene(this.startScene.sceneWithSelf()); // Though maybe change the variable name startScene .
If you don’t want to change main.js, then you should create your own scene class and have it do it’s work in the constructor function.