Jump to content

How to fix: Uncaught TypeError: Cannot read property 'onComplete' of undefined


ibb671
 Share

Recommended Posts

Hello I was wondering what would be causing this error this is the section of code that i think its causing this error. Sorry i'm still learning about javascript and phaser in general.

Thanks in advanced for you guys again for your help.

 

 

if(element.frame==6/){
				enemy++;
				
				if(enemy>5 && element.frame==6){
					this.mothersDayItems.forEachAlive(function(element2){
						if(element2.frame==6){
							var enemyTween = me.game.add.tween(enemySprite).to({
								alpha:0,
							},2000,Phaser.Easing.Linear.Out,true);

							me.enemyTween.onComplete(function(){
								element2.kill();
								element2.alpha=1;
							});
								
							
						}
						enemy=0;
						
					},me);
					
					
					//element.kill();
				}

				/*this.particleBurst(element.x,element.y-20);*/
			}

 

Link to comment
Share on other sites

Don't know what "me" is, but I'm pretty sure that "me" doesn't know about any tween.

Just from that example, I'd try this:

enemyTween.onComplete.add(function() {
	element2.kill();
	element2.alpha = 1;
}, this);

since enemyTween is just a local variable. Note that you can't assign the function to onComplete, you must go with onComplete.add(). Usually you must also add a callback context (the "this" on the last line).

If you won't need the tween later, you can go straight like this without assigning it to a variable:

me.game.add.tween(enemySprite)
    .to({alpha: 0}, 2000, Phaser.Easing.Linear.Out, true)
    .onComplete
    .add(function(){
        element2.kill();
        element2.alpha = 1;
    }, this);

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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