Jump to content

Cannot execute function


oliversb
 Share

Recommended Posts

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

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();}
Link to comment
Share on other sites

 

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

What is

this.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

 

What is

this.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:20
It 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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...