fran Posted February 17, 2015 Share Posted February 17, 2015 Hello, I'm trying to define a few objects with their names + properties using classes.I can have new Goals at creation, however I'm stuck with prototypes.So far it's: //***************** OBJECTSfunction Goal(nombre, posX, posY){ this.nombre = nombre; this.posX = posY; this.posY=posY; //console.log ('nombre: '+ this.nombre+ ' pos x: '+this.posX); this.sp = game.add.sprite(posX,posY, 'bola'); game.physics.enable(this.sp, Phaser.Physics.ARCADE); this.sp.body.immovable = false; this.sp.body.collideWorldBounds = true; this.sp.body.bounce.setTo(1, 1); this.sp.inputEnabled = true; this.sp.events.onInputDown.add(listener1, this); /*this.listener1 = function(){ console.log (this.name + 'was cliked!'); }*/}Goal.prototype.listener1 = function() { console.log (this.name + 'was cliked!');}My goal was to know which object was clicked (using listener1).I get a console message:ReferenceError: listener1 is not definedThanks for the patience and the advice on how to fix this.regards. Link to comment Share on other sites More sharing options...
Triplanetary Posted February 17, 2015 Share Posted February 17, 2015 this.sp.events.onInputDown.add(listener1, this); Should be: this.sp.events.onInputDown.add(this.listener1, this); Link to comment Share on other sites More sharing options...
fran Posted February 17, 2015 Author Share Posted February 17, 2015 Thanks a lot! Link to comment Share on other sites More sharing options...
Recommended Posts