oliversb Posted May 30, 2014 Share Posted May 30, 2014 I cannot work out why I cannot call this function. I am basically creating a 'constructor' that gets called after all the objects are added to a particular state. In the executeConstructors function, it tells me that the constructor is undefined. I tried to define the function theConstructor like this: function pmOBJECTObject(x, y, key) {Phaser.Sprite.call(this, x ,y, key);function theConstructor () {this.pmIfThen4();}}pmOBJECTObject.prototype = Object.create(Phaser.Sprite.prototype);pmOBJECTObject.prototype.constructor = Phaser.Sprite; I changed the code from the original to make it quicker to read and so people can help more easily. This is the executeConstructors function and it is having problems executing the theConstructor function:function executeConstructors() {for (var i = 0; i < game.stage.children.length; i ++) {game.stage.children.theConstructor();}} I don't think it needs to be put on a local server because it does not use the file system (I think). I have linked a build of my project here:https://www.dropbox.com/sh/sfq9yltugecvzc1/AAAnHQKxPSUJpaslGGq7-a4Ja Thanks Link to comment Share on other sites More sharing options...
XekeDeath Posted May 30, 2014 Share Posted May 30, 2014 This is a problem here:pmOBJECTObject.prototype.constructor = Phaser.Sprite;You are saying that the constructor for your pmOBJECTObject is the Phaser.Sprite one, not the one you just defined.But I see this is different in the source you have on dropbox.I also see that there is no 'theConstructor' function anywhere in that code. Have you considered adding theConstructor to the pmOBJECTObject prototype instead of declaring it inside the constructor?function pmOBJECTObject(x, y, key) { Phaser.Sprite.call(this, x ,y, key);}pmOBJECTObject.prototype = Object.create(Phaser.Sprite.prototype);pmOBJECTObject.prototype.constructor = pmOBJECTObject;pmOBJECTObject.prototype.theConstructor = function() { this.pmIfThen4();} oliversb 1 Link to comment Share on other sites More sharing options...
oliversb Posted May 30, 2014 Author Share Posted May 30, 2014 This is a problem here:pmOBJECTObject.prototype.constructor = Phaser.Sprite;You are saying that the constructor for your pmOBJECTObject is the Phaser.Sprite one, not the one you just defined.But I see this is different in the source you have on dropbox.I also see that there is no 'theConstructor' function anywhere in that code. Have you considered adding theConstructor to the pmOBJECTObject prototype instead of declaring it inside the constructor?function pmOBJECTObject(x, y, key) { Phaser.Sprite.call(this, x ,y, key);}pmOBJECTObject.prototype = Object.create(Phaser.Sprite.prototype);pmOBJECTObject.prototype.constructor = pmOBJECTObject;pmOBJECTObject.prototype.theConstructor = function() { this.pmIfThen4();}I have considered that. It does not seem to work. I tried this: function pmOBJECTObject(x, y, key) {this.pmVARG = 12;this.pmVARa = "Hello world!";this.pmVARb = "Hello world!"; //pmOBJECTObject PowerModeObject.call(this, x ,y, key);}pmOBJECTObject.prototype = Object.create(PowerModeObject.prototype);pmOBJECTObject.prototype.constructor = pmOBJECTObject;pmOBJECTObject.prototype.theConstructor = function () {this.pmIfThen4();//pmOBJECTObjectConstructor} Thanks Link to comment Share on other sites More sharing options...
XekeDeath Posted May 30, 2014 Share Posted May 30, 2014 What isthis.pmIfThen4();That is the only thing I have not seen mention of anywhere else.What is the exact error message in the console when you try run the code? Also, it was late when I wrote the example, the first function was supposed to be:pmOBJECTObject = function (x, y, key){ Phaser.Sprite.call(this, x ,y, key);} Link to comment Share on other sites More sharing options...
oliversb Posted May 31, 2014 Author Share Posted May 31, 2014 What isthis.pmIfThen4();That is the only thing I have not seen mention of anywhere else.What is the exact error message in the console when you try run the code? Also, it was late when I wrote the example, the first function was supposed to be:pmOBJECTObject = function (x, y, key){ Phaser.Sprite.call(this, x ,y, key);}this.pmIfThen4() is a test function. I am developing a programming tool and it generates code for me. It is nothing more than a test to see if get errors in the console. Here is the error Uncaught TypeError: undefined is not a function PowerModeEngine.js:20It links to this line of code:game.stage.children.theConstructor(); The code that I uploaded might be different because I attempted to create an array that stores all the sprites then I found it still didn't work so I switched to using the built-in array. Thanks Link to comment Share on other sites More sharing options...
oliversb Posted June 1, 2014 Author Share Posted June 1, 2014 'Phaser.Sprite.call(this, x ,y, key);', Sorry. That was just a mistake when writing out the code. I tried to modify the code so it was quicker to read. Link to comment Share on other sites More sharing options...
XekeDeath Posted June 2, 2014 Share Posted June 2, 2014 So the code you are working on is different to the code you uploaded which is different to the code in the post...? Link to comment Share on other sites More sharing options...
oliversb Posted June 2, 2014 Author Share Posted June 2, 2014 Thanks. Yes. But make things less confusing. Nothing matters apart from the code on Dropbox. I did not realise there was a bug with the code I wrote up here. Link to comment Share on other sites More sharing options...
oliversb Posted June 3, 2014 Author Share Posted June 3, 2014 So the code you are working on is different to the code you uploaded which is different to the code in the post...?BUMP Link to comment Share on other sites More sharing options...
Recommended Posts