Video onComplete function is called multiple times #2303
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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);
}