export class Example extends Phaser.GameObjects.Container {
constructor(scene, x = 0, y = 0) {
super(scene, x, y);
this.form = this.scene.add.dom(300, 400).createFromCache("example");
const name = this.form.getChildByName("company-name");
name.setText("Some text");
}
}
The setText call results in a TypeError because the name variable is null. If I wrap the setText call in a 1 second setTimeout, there is no error because the DOM node is present in the DOM. I was assuming there would be an event listener I could hook into to modify the DOM element once it’s loaded, but I can’t find one.
I did try that yesterday, and again just now, but the callback never gets called. I can see the content displayed on screen, so I know it’s been loaded. Reading around it yesterday, it seems there’s no DOM event fired when new DOM elements are added.
var element = this.add.dom(400, 300).createFromCache('nameform');
var field = element.getChildByName('username');
console.assert(field);
console.log(field);
This won’t work as an HTML element has no setText() method. Probably it should be
Thanks samme, it wasn’t quite that but you did set me looking the right direction. Firstly I should have been using getChildByID, and then to set the value, it’s the textContent property.