# Problem with Container?

**URL:** <https://phaser.discourse.group/t/problem-with-container/4633>\
**Category:** Phaser 3\
**Created:** [December 17, 2019, 6:31pm UTC](https://phaser.discourse.group/t/problem-with-container/4633 "2019-12-17T18:31:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thundros](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/thundros/32/2057_2.png) [@Thundros](https://phaser.discourse.group/u/Thundros)\
**Post date:** [December 17, 2019, 6:31pm UTC](https://phaser.discourse.group/t/problem-with-container/4633/1 "2019-12-17T18:31:26Z")

</div>

Here’s a link to my project :

[https://thundros.github.io/menu-system-doosan/](https://thundros.github.io/menu-system-doosan/)

so I have uploaded a new `'ContainerScene.js'` at :

& I am trying to figure out inside of :

[https://thundros.github.io/menu-system-doosan/src/Scenes/ContainerScene.js](https://thundros.github.io/menu-system-doosan/src/Scenes/ContainerScene.js)

&

[https://thundros.github.io/menu-system-doosan/src/Scenes/OptionsScene.js](https://thundros.github.io/menu-system-doosan/src/Scenes/OptionsScene.js)

I’m trying to fix :

```javascript
phaser.js:36795 Uncaught TypeError: Cannot read property 'once' of undefined

```

I’m wondering why it’s not letting me do :

```javascript
this.__container.create ({
	scene : this, x : 100, y : 100, 
	w : 100, h : 100, useChildIndex : true, 
	childData : [
		this.__myArrowLeft, 
		this.__myArrowRight,  
	]
});

```

Here is the `'create ( )'` function from `'ContainerScene.js'` :

```javascript
create : function ( __objData ) {

	this. __objData =__ objData;
	this. __childData = this.__ objData.childData;

	this. __scene = this.__ objData.scene;
	this. __x = this.__ objData.x;
	this. __y = this.__ objData.y;
	this. __w = this.__ objData.w;
	this. __h = this.__ objData.h;

	this. __useChildIndex = this.__ objData.useChildIndex;

	if ( this.__useChildIndex === true ) {
		if ( typeof ( this.__childData ) === 'object' ) {
			if ( this.emptyObject ( this.__childData ) ) {
				return console.error (
					'\r\n' + 
						'CHILD DATA DOES NOT EXIST!' + '\r\n' + 
						'PLEASE ADD CHILD DATA & TRY AGAIN!' + 
					'\r\n\r\n'
				);
			}
		}
	}

	if ( this.__useChildIndex === true ) {

		this. __child = this.__ childData.children;
		this. __childIndex = this.__ childData.index;

		console.error ( this.__child );

		// console.error ( this.__childIndex );

	}

	this. __useScrollFactor = this.__ objData.useScrollFactor;
	this. __setNonExclusive = this.__ objData.setNonExclusive;
	this. __setInteractive = this.__ objData.setInteractive;
	this. __interactiveGeometry = this.__ objData.intGeom;
	this. __contains = this.__ objData.contains;

	this. __container = this.__ scene.add.container (
		this.__x, 
		this.__y
	);

	this.__container.setSize (
		this.__w, 
		this.__h
	);

	if ( this.__objData.useChildIndex === false ) {

		this.__container.add ( this.__child );

	}

	if ( this.__useChildIndex === true ) {

		this.__container.addAt (
			this.__child, 
			this.__childIndex
		);

	}

	if ( this.__useScrollFactor === true ) {

		this.__container.setScrollFactor (
			this.__scrollX, 
			this.__scrollY
		);

	}

	if ( this.__useScrollFactorChildren === true ) {

		this.__container.setScrollFactor (
			this.__scrollX, 
			this.__scrollY, 
			true
		);

	}

	if ( this.__setInteractive === true ) {

		this.__container.setInteractive (
			this.__interactiveGeometry, 
			this.__contains
		);

	}

	if ( this.__setNonExclusive === true ) {

		this.__container.setExclusive ( false );

	}

	return this.__container;

}, 

```

Any help is GREATLY appreciated! 🙂

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [December 17, 2019, 9:02pm UTC](https://phaser.discourse.group/t/problem-with-container/4633/2 "2019-12-17T21:02:33Z")

</div>

It should extend Scene, not Container.

---

<div class="post-metadata">

**Author:** ![Thundros](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/thundros/32/2057_2.png) [@Thundros](https://phaser.discourse.group/u/Thundros)\
**Post date:** [December 18, 2019, 4:10pm UTC](https://phaser.discourse.group/t/problem-with-container/4633/3 "2019-12-18T16:10:39Z")

</div>

Did that. I still can’t get it to put my text in the containers properly & allow me to move whatever has been added to the container all at once by moving the container itself.

[https://thundros.github.io/menu-system-doosan/src/Scenes/ContainerScene.js](https://thundros.github.io/menu-system-doosan/src/Scenes/ContainerScene.js)

Specifically, `'line{s} 67 - 102 '`.

Here’s the part of the code I’m talking about :

```javascript
// For each Child
for ( this. __i = 0; this.__ i < this. __childDataCount; this.__ i++ ) {
	// If `use Child index` is `true`
	if ( this.__useChildIndex === true ) {
		// Set `this.__children [...]` to 
		// `this.__childData [this.__i]`
		this.__children [this.__i] = this.__childData [this.__i];
		// Set the `Child` index
		this.__childIndex [this.__i] = this.__i;
		// If `this.__children [this.__i]`'s type 
		// is an object
		if ( typeof ( this.__children [this.__i] ) === 'object' ) {
			// If that `object is `NOT` `empty`
			if ( this.emptyObject ( this.__children [this.__i] ) === false ) {
				// If `NOT` using a `Child index`
				if ( this.__objData.useChildIndex === false ) {
					// Log A
					console.log ( 'A' );
					// Add the `children` 
					// to `container`
					this.__container.add ( this.__children [this.__i] );
				}
				// `IF` using a `Child index`
				if ( this.__objData.useChildIndex === true ) {
					// Log B
					console.log ( 'B' );
					// Set the `Child` to 
					// `index [i]`
					this.__container.addAt (
						this.__children [this.__i], 
						this.__childIndex [this.__i]
					);
				}
			}
		}
	}
}

```

Any help is GREATLY appreciated! =)

---

<div class="post-metadata">

**Author:** ![Thundros](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/thundros/32/2057_2.png) [@Thundros](https://phaser.discourse.group/u/Thundros)\
**Post date:** [December 18, 2019, 6:08pm UTC](https://phaser.discourse.group/t/problem-with-container/4633/4 "2019-12-18T18:08:10Z")

</div>

someone can help me please?

---

<div class="post-metadata">

**Author:** ![jjcapellan](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/jjcapellan/32/542_2.png) [@jjcapellan](https://phaser.discourse.group/u/jjcapellan)\
**Post date:** [December 18, 2019, 6:48pm UTC](https://phaser.discourse.group/t/problem-with-container/4633/5 "2019-12-18T18:48:48Z")

</div>

Hi @Thundros  
First check if `this.__childDataCount` is 0 or undefined.  
Regards.

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [December 18, 2019, 6:56pm UTC](https://phaser.discourse.group/t/problem-with-container/4633/6 "2019-12-18T18:56:51Z")

</div>

Are you stepping through your code?
