Phaser API Documentation

  Version: 
createFromCache(The, [tagName])

Description:

Takes a block of html from the HTML Cache, that has previously been preloaded into the game, and then creates a DOM Element from it. The loaded HTML is set as the innerHTML property of the created element.

Assume the following html is stored in a file called loginform.html:

<input type="text" name="nameField" placeholder="Enter your name" style="font-size: 32px">
<input type="button" name="playButton" value="Let's Play" style="font-size: 32px">

Which is loaded into your game using the cache key 'login':

this.load.html('login', 'assets/loginform.html');

You can create a DOM Element from it using the cache key:

this.add.dom().createFromCache('login');

The optional elementType argument controls the container that is created, into which the loaded html is inserted. The default is a plain div object, but any valid tagName can be given.

If this Game Object already has an Element, it is removed from the DOM entirely first. Any event listeners you may have previously created will need to be re-created after this call.

Parameters:

name type arguments Default description
The string

key of the html cache entry to use for this DOM Element.

tagName string <optional> 'div'

The tag name of the element into which all of the loaded html will be inserted. Defaults to a plain div tag.

Returns:
Description:

This DOM Element instance.

Since: 3.17.0