Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Help with accessing a containers children


ShadowMoon
 Share

Recommended Posts

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

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...