Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Video onComplete function is called multiple times #2303

Closed
wants to merge 2 commits into from

Conversation

ramalhovfc
Copy link

Video onComplete added functions are called multiples times when video playback ends. This is because a bind() is called on the function passed to removeEventListener. Because bind always returns a new function, the system can not find (and remove) the previous event listeners. The functions added to the onComplete signal will be called the same number of times that the video plays (first time: one; second time: two...).

To reproduce the problem paste the following code in a phaser example page,for example: http://phaser.io/examples/v2/video/alpha-webm

var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create });
function preload() {
game.load.video('space', 'assets/video/alpha-webm.webm');
}
var video;
function create() {
video = game.add.video('space');
video.onComplete.add(function() {alert('On complete called'); video.play();});
video.play();
video.addToWorld(400, 300, 0.5, 0.5);
}

… was called multiple times because removeEventListener was being called using bing(), which always returns a new function.
photonstorm added a commit that referenced this pull request Feb 2, 2016
…ended' and 'playing' event listeners, meaning that they were never removed properly (thanks @ramalhovfc #2303)
@photonstorm
Copy link
Collaborator

Thanks for the PR. I can't merge because it's against the wrong branch, but have made the changes locally.

@photonstorm photonstorm closed this Feb 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants