From 34aff350eb0d0d421d56a727353f2a49a0bbf5d2 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Tue, 2 Feb 2016 00:18:38 +0000 Subject: [PATCH] The Video game object used an anonymous bound function for both the 'ended' and 'playing' event listeners, meaning that they were never removed properly (thanks @ramalhovfc #2303) --- README.md | 2 ++ src/gameobjects/Video.js | 25 ++++++++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5bf1360cc..8f28981ec 100644 --- a/README.md +++ b/README.md @@ -271,6 +271,7 @@ If you are an exceptional JavaScript developer and would like to join the Phaser * You can use the new const `Phaser.PENDING_ATLAS` as the texture key for any sprite. Doing this then sets the key to be the `frame` argument (the frame is set to zero). This allows you to create sprites using `load.image` during development, and then change them to use a Texture Atlas later in development by simply searching your code for 'PENDING_ATLAS' and swapping it to be the key of the atlas data. * BitmapText.cleanText is a new method that will scan the given text and either remove or replace all characters that are not present in the font data. It is called automatically by `BitmapText.updateText`. +* ArcadePhysics.Body.onCeiling is a new complementary method to go with onFloor (thanks @yigitozdemir #1610) ### Updates @@ -299,6 +300,7 @@ If you are an exceptional JavaScript developer and would like to join the Phaser * When loading audio or video from blob or data URIs, the local variable was replaced too soon, throwing errors in `getAudioURL` and `getVideoURL` (thanks @milkey-mouse @jackfreak #2236 #2234) * Tween.hasStarted parameter was set to `false` when the tween was created, but not set again when the tween was stopped or ends. If `Tween.start` is used more than once the `onStart` callback is called only the first time (thanks @javivi91 #2199) * During a WebGL context loss the Phaser Cache was referencing the wrong local object (thanks @allenevans #2285) +* The Video game object used an anonymous bound function for both the 'ended' and 'playing' event listeners, meaning that they were never removed properly (thanks @ramalhovfc #2303) ### Pixi Updates diff --git a/src/gameobjects/Video.js b/src/gameobjects/Video.js index 8ef01165c..c58d9cb21 100644 --- a/src/gameobjects/Video.js +++ b/src/gameobjects/Video.js @@ -205,6 +205,18 @@ Phaser.Video = function (game, key, url) { */ this._autoplay = false; + /** + * @property {function} _endCallback - The addEventListener ended function. + * @private + */ + this._endCallback = null; + + /** + * @property {function} _playCallback - The addEventListener playing function. + * @private + */ + this._playCallback = null; + if (key && this.game.cache.checkVideoKey(key)) { var _video = this.game.cache.getVideo(key); @@ -644,7 +656,9 @@ Phaser.Video.prototype = { this.game.onPause.add(this.setPause, this); this.game.onResume.add(this.setResume, this); - this.video.addEventListener('ended', this.complete.bind(this), true); + this._endCallback = this.complete.bind(this); + + this.video.addEventListener('ended', this._endCallback, true); if (loop) { @@ -674,7 +688,8 @@ Phaser.Video.prototype = { } else { - this.video.addEventListener('playing', this.playHandler.bind(this), true); + this._playCallback = this.playHandler.bind(this); + this.video.addEventListener('playing', this._playCallback, true); } } @@ -695,7 +710,7 @@ Phaser.Video.prototype = { */ playHandler: function () { - this.video.removeEventListener('playing', this.playHandler.bind(this)); + this.video.removeEventListener('playing', this._playCallback, true); this.updateTexture(); @@ -754,8 +769,8 @@ Phaser.Video.prototype = { } else { - this.video.removeEventListener('ended', this.complete.bind(this), true); - this.video.removeEventListener('playing', this.playHandler.bind(this), true); + this.video.removeEventListener('ended', this._endCallback, true); + this.video.removeEventListener('playing', this._playCallback, true); if (this.touchLocked) {