ShadowMoon Posted May 17, 2018 Share Posted May 17, 2018 So in my create function I make a container, populate it with a sprite 25 times in random positions and rotation. If I put console.log(container.length); I get 25. All good so far. But when I try to access it within an event I always get undefined. No matter how I try to call the container or it's children. I have tried 100 different ways. Including every combination of the this keyword. Little off topic, but I seem to really struggle with the this keyword and it's use in phaser. Constantly have problems accessing variables and such, with undefined errors. Is there a good tutorial for that? Is this more of javascript thing or phaser. Anyway this is the code after I create the container. It returns undefined, undefined this.input.on('pointerdown', function(container){ console.log(container[0]); console.log(container.length); for(var i = 0; i < container.length; i++){ console.log(i); container[i].setTint(Math.random() * 0xffffff); } }); Thank you. Link to comment Share on other sites More sharing options...
wclarkson Posted May 17, 2018 Share Posted May 17, 2018 What you are looking for is container.list[0] and container.list.length. It is a bit confusing as so many other things use children. Link to comment Share on other sites More sharing options...
ShadowMoon Posted May 17, 2018 Author Share Posted May 17, 2018 7 minutes ago, wclarkson said: What you are looking for is container.list[0] and container.list.length. It is a bit confusing as so many other things use children. That just gives me: Uncaught TypeError: Cannot read property 'list' of undefined another undefined error, added the this keyword also/ this.container.list[0] and this.container.list.length same output Link to comment Share on other sites More sharing options...
squilibob Posted May 17, 2018 Share Posted May 17, 2018 Did you call .setInteractive() on the sprites or on the container? Link to comment Share on other sites More sharing options...
wclarkson Posted May 22, 2018 Share Posted May 22, 2018 Log out your container to the console this.input.on('pointerdown', function(container){ console.log(container); }); That will give you a list of all the properties and children. Link to comment Share on other sites More sharing options...
Recommended Posts