# Hi campers. about coding structure

**URL:** <https://phaser.discourse.group/t/hi-campers-about-coding-structure/2828>\
**Category:** Phaser 3\
**Created:** [June 19, 2019, 1:27pm UTC](https://phaser.discourse.group/t/hi-campers-about-coding-structure/2828 "2019-06-19T13:27:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![donjon1234](https://avatars.discourse-cdn.com/v4/letter/d/ba8739/32.png) [@donjon1234](https://phaser.discourse.group/u/donjon1234)\
**Post date:** [June 19, 2019, 1:27pm UTC](https://phaser.discourse.group/t/hi-campers-about-coding-structure/2828/1 "2019-06-19T13:27:49Z")

</div>

Hi, I am trying to access the “my-scene” class instance in javascript and call a method.  
But I failed so far… its more of design pattern question, but I call

```
 let cor= this.game.scene.add('Scene', new MyScene(), true); setInterval(()=>{

```

etc…  
how do I access that myscene instance? and call a method is it possible?  
or the other way around how to make an event that arrives at the main class from my scene?

---

<div class="post-metadata">

**Author:** ![donjon1234](https://avatars.discourse-cdn.com/v4/letter/d/ba8739/32.png) [@donjon1234](https://phaser.discourse.group/u/donjon1234)\
**Post date:** [June 19, 2019, 2:11pm UTC](https://phaser.discourse.group/t/hi-campers-about-coding-structure/2828/2 "2019-06-19T14:11:20Z")

</div>

I find out that it is possible to send events, like so  
`cor.=> cor.events.addListener('abra',this.br)`  
so it kind of listening for events in the instance.  
Maybe can work I need to test more but thanks anyways

---

<div class="post-metadata">

**Author:** ![Sturb](https://avatars.discourse-cdn.com/v4/letter/s/df788c/32.png) [@Sturb](https://phaser.discourse.group/u/Sturb)\
**Post date:** [June 19, 2019, 2:50pm UTC](https://phaser.discourse.group/t/hi-campers-about-coding-structure/2828/3 "2019-06-19T14:50:19Z")

</div>

Try:

```javascript
this.game.scene.add('Scene', MyScene, true);
let cor = this.game.scene.getScene('Scene');

```

[https://photonstorm.github.io/phaser3-docs/Phaser.Scenes.SceneManager.html#getScene](https://photonstorm.github.io/phaser3-docs/Phaser.Scenes.SceneManager.html#getScene)

---

<div class="post-metadata">

**Author:** ![donjon1234](https://avatars.discourse-cdn.com/v4/letter/d/ba8739/32.png) [@donjon1234](https://phaser.discourse.group/u/donjon1234)\
**Post date:** [June 19, 2019, 3:35pm UTC](https://phaser.discourse.group/t/hi-campers-about-coding-structure/2828/4 "2019-06-19T15:35:51Z")

</div>

yes it works but in my `class 'myscene`’ instance there is for example an increment method, how do i access it from the main class?  
this is not working.  
`cor.increment()`  
=)  
anyway thanks

---

<div class="post-metadata">

**Author:** ![Sturb](https://avatars.discourse-cdn.com/v4/letter/s/df788c/32.png) [@Sturb](https://phaser.discourse.group/u/Sturb)\
**Post date:** [June 19, 2019, 7:24pm UTC](https://phaser.discourse.group/t/hi-campers-about-coding-structure/2828/5 "2019-06-19T19:24:18Z")

</div>

Technically, if you use getScene(…) to get your scene object, you should be able to just call the function on it normally `cor.myFunction(...)`.

Without knowing the extent of what you’re trying to do, for me this is a weird way to use scenes. So one thing you could do is in your MyScene object add a listener to an ‘increment’ event, then outside of it you can go `cor.emit('increment');`.

---

<div class="post-metadata">

**Author:** ![donjon1234](https://avatars.discourse-cdn.com/v4/letter/d/ba8739/32.png) [@donjon1234](https://phaser.discourse.group/u/donjon1234)\
**Post date:** [June 20, 2019, 11:05am UTC](https://phaser.discourse.group/t/hi-campers-about-coding-structure/2828/6 "2019-06-20T11:05:00Z")

</div>

Yes I stumbled on the event it is clear the event prototype is working at least, Yes it is maybe a bit odd to use it that way, I am just looking for ways to implement more game data and values in the HTML GUI.  
But thanks mate if I type Myscene.prototype. =\> all methods pop up though so I am not sure how to use it yet, but thanks for your input!
