# \[SOLVED\] Custom Event emitter communication across Scenes

**URL:** <https://phaser.discourse.group/t/solved-custom-event-emitter-communication-across-scenes/529>\
**Category:** Phaser 3\
**Created:** [December 30, 2018, 2:23pm UTC](https://phaser.discourse.group/t/solved-custom-event-emitter-communication-across-scenes/529 "2018-12-30T14:23:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![freddyatlantis](https://avatars.discourse-cdn.com/v4/letter/f/dc4da7/32.png) [@freddyatlantis](https://phaser.discourse.group/u/freddyatlantis)\
**Post date:** [December 30, 2018, 2:23pm UTC](https://phaser.discourse.group/t/solved-custom-event-emitter-communication-across-scenes/529/1 "2018-12-30T14:23:08Z")

</div>

Hi, I have a HUDScene and a LEVEL\_1Scene. In a SceneController extends Phaser.Scene, i have a create() function which does this:

> Blockquote  
> this.scene.start(CST.SCENES.LEVEL\_1);  
> this.scene.launch(CST.SCENES.HUD);

I also have a controller.js class with constants for event emission. If i launch the HUDScene first, then start the LEVEL\_1Scene, level1 event.emit isnt received by the HUD. However, if I start level 1 first, then lauch the HUD, everything works as planned.

Can anyone explain what is going on here? Or point me to an online explanation (other than Phaser 3 Docs and Notes, ive searched all over these sites, and havent found something like this addressed).

thanks in advance

---

<div class="post-metadata">

**Author:** ![Telokis](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/telokis/32/297_2.png) [@Telokis](https://phaser.discourse.group/u/Telokis)\
**Post date:** [December 31, 2018, 10:00am UTC](https://phaser.discourse.group/t/solved-custom-event-emitter-communication-across-scenes/529/2 "2018-12-31T10:00:14Z")

</div>

I think we will need to see a bit more code in order to understand your problem.  
What is your error, exactly? How do you pass the EventEmitter to your scenes? How do you emit/listen to events?

---

<div class="post-metadata">

**Author:** ![freddyatlantis](https://avatars.discourse-cdn.com/v4/letter/f/dc4da7/32.png) [@freddyatlantis](https://phaser.discourse.group/u/freddyatlantis)\
**Post date:** [January 4, 2019, 11:08pm UTC](https://phaser.discourse.group/t/solved-custom-event-emitter-communication-across-scenes/529/3 "2019-01-04T23:08:45Z")

</div>

thanks for the reply telokis. i did a lot of actionscript 3 coding years ago, so i dont have a hard time with javascript, but i’m not really sure how event emitters work in phaser 3.

these are the first two lines in my create() function of each scene

> Blockquote  
> emitter = new Phaser.Events.EventEmitter();

the emitter sends out info like this

> Blockquote  
> emitter.emit(G.SCORE\_UPDATED, 1);

and the listeners are something like this

> Blockquote  
> emitter.on(G.SCORE\_UPDATED, this.scoreUpdated, this);

event constants are in a seperate .js file.

if events are emitted by sceneA, and the listener is in sceneB, it’s a 50/50. sometimes they work, sometimes not so much.

so what i’m wondering first of all is, should i instantiate an emitter somewhere globally? would that be the proper way to go about it? or do i have to instantiate one in every scene?

---

<div class="post-metadata">

**Author:** ![freddyatlantis](https://avatars.discourse-cdn.com/v4/letter/f/dc4da7/32.png) [@freddyatlantis](https://phaser.discourse.group/u/freddyatlantis)\
**Post date:** [January 6, 2019, 12:47am UTC](https://phaser.discourse.group/t/solved-custom-event-emitter-communication-across-scenes/529/4 "2019-01-06T00:47:55Z")

</div>

okay, after flailing around with ES6, webpack, node, and singletons, i found out what my problem was.

the behavior was that sometimes events would be emitted by one scene and should have been received by another scene, at least thats what i thought. sometimes events were received, and sometimes not.

actually, all of my events werent being emitted by a scene at all, rather, sometimes i was trying to emit an event via a class object that didnt extend a scene.

once i put emitter references into the classes, they emit and receive just the way they should.

hope that helps someone else.

---

<div class="post-metadata">

**Author:** ![piotr](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/piotr/32/4698_2.png) [@piotr](https://phaser.discourse.group/u/piotr)\
**Post date:** [February 23, 2021, 2:41pm UTC](https://phaser.discourse.group/t/solved-custom-event-emitter-communication-across-scenes/529/5 "2021-02-23T14:41:36Z")

</div>

How did you add references into the classes?
