Phaser API Documentation

  Version: 
Filter

A single HTML File suitable for loading by the Loader.

These are created when you use the Phaser.Loader.LoaderPlugin#html method and are not typically created directly.

For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#html.

Constructor:

new HTMLFile(loader, key, [url], [xhrSettings])

Parameters:

name type arguments description
loader Phaser.Loader.LoaderPlugin

A reference to the Loader that is responsible for this file.

key string | Phaser.Types.Loader.FileTypes.HTMLFileConfig

The key to use for this file, or a file configuration object.

url string <optional>

The absolute or relative URL to load this file from. If undefined or null it will be set to <key>.html, i.e. if key was "alien" then the URL will be "alien.html".

xhrSettings Phaser.Types.Loader.XHRSettingsObject <optional>

Extra XHR Settings specifically for this file.

Since: 3.12.0

Extends


Members

base64: boolean
Focus
Focus

Description:

Does this File contain a data URI?

Type:
boolean
Inherited from: Phaser.Loader.File#base64
Since: 3.80.0
Source: src/loader/File.js (Line 236)
Focus
Focus
bytesLoaded: number
Focus
Focus

Description:

Updated as the file loads. Only set if loading via XHR.

Type:
number
Default: -1
Inherited from: Phaser.Loader.File#bytesLoaded
Since: 3.0.0
Source: src/loader/File.js (Line 165)
Focus
Focus
bytesTotal: number
Focus
Focus

Description:

The total size of this file. Set by onProgress and only if loading via XHR.

Type:
number
Default: 0
Inherited from: Phaser.Loader.File#bytesTotal
Since: 3.0.0
Source: src/loader/File.js (Line 154)
Focus
Focus

Description:

A reference to the Cache, or Texture Manager, that is going to store this file if it loads.

Type:
Inherited from: Phaser.Loader.File#cache
Since: 3.7.0
Source: src/loader/File.js (Line 44)
Focus
Focus
config: *
Focus
Focus

Description:

A config object that can be used by file types to store transitional data.

Type:
*
Inherited from: Phaser.Loader.File#config
Since: 3.0.0
Source: src/loader/File.js (Line 206)
Focus
Focus
crossOrigin: string | undefined
Focus
Focus

Description:

For CORs based loading. If this is undefined then the File will check BaseLoader.crossOrigin and use that (if set)

Type:
string | undefined
Inherited from: Phaser.Loader.File#crossOrigin
Since: 3.0.0
Source: src/loader/File.js (Line 187)
Focus
Focus
data: *
Focus
Focus

Description:

The processed file data, stored here after the file has loaded.

Type:
*
Inherited from: Phaser.Loader.File#data
Since: 3.0.0
Source: src/loader/File.js (Line 197)
Focus
Focus
key: string
Focus
Focus

Description:

Unique cache key (unique within its file type)

Type:
string
Inherited from: Phaser.Loader.File#key
Since: 3.0.0
Source: src/loader/File.js (Line 67)
Focus
Focus
<nullable> linkFile: Phaser.Loader.File
Focus
Focus

Description:

Does this file have an associated linked file? Such as an image and a normal map. Atlases and Bitmap Fonts use the multiFile, because those files need loading together but aren't actually bound by data, where-as a linkFile is.

Type:
Inherited from: Phaser.Loader.File#linkFile
Since: 3.7.0
Source: src/loader/File.js (Line 225)
Focus
Focus

Description:

A reference to the Loader that is going to load this file.

Type:
Inherited from: Phaser.Loader.File#loader
Since: 3.0.0
Source: src/loader/File.js (Line 35)
Focus
Focus
<nullable> multiFile: Phaser.Loader.MultiFile
Focus
Focus

Description:

If this is a multipart file, i.e. an atlas and its json together, then this is a reference to the parent MultiFile. Set and used internally by the Loader or specific file types.

Type:
Inherited from: Phaser.Loader.File#multiFile
Since: 3.7.0
Source: src/loader/File.js (Line 215)
Focus
Focus
percentComplete: number
Focus
Focus

Description:

A percentage value between 0 and 1 indicating how much of this file has loaded. Only set if loading via XHR.

Type:
number
Default: -1
Inherited from: Phaser.Loader.File#percentComplete
Since: 3.0.0
Source: src/loader/File.js (Line 176)
Focus
Focus
retryAttempts: number
Focus
Focus

Description:

The counter for the number of times to retry loading this file before it fails.

You can set this property value in the FileConfig object. If not present, this property is read from the LoaderPlugin.maxRetries property when this File instance is created.

You can set this value via the Game Config, or you can adjust the LoaderPlugin property at any point after the Loader has started. However, it will not apply to files that have already been added to the Loader, only those added after this value is changed.

Type:
number
Default: 2
Inherited from: Phaser.Loader.File#retryAttempts
Since: 3.85.0
Source: src/loader/File.js (Line 245)
Focus
Focus
src: string
Focus
Focus

Description:

The final URL this file will load from, including baseURL and path. Set automatically when the Loader calls 'load' on this file.

Type:
string
Inherited from: Phaser.Loader.File#src
Since: 3.0.0
Source: src/loader/File.js (Line 112)
Focus
Focus
state: number
Focus
Focus

Description:

The current state of the file. One of the FILE_CONST values.

Type:
number
Inherited from: Phaser.Loader.File#state
Since: 3.0.0
Source: src/loader/File.js (Line 145)
Focus
Focus
type: string
Focus
Focus

Description:

The file type string (image, json, etc) for sorting within the Loader.

Type:
string
Inherited from: Phaser.Loader.File#type
Since: 3.0.0
Source: src/loader/File.js (Line 53)
Focus
Focus
url: object | string
Focus
Focus

Description:

The URL of the file, not including baseURL.

Automatically has Loader.path prepended to it if a string.

Can also be a JavaScript Object, such as the results of parsing JSON data.

Type:
object | string
Inherited from: Phaser.Loader.File#url
Since: 3.0.0
Source: src/loader/File.js (Line 99)
Focus
Focus
<nullable> xhrLoader: XMLHttpRequest
Focus
Focus

Description:

The XMLHttpRequest instance (as created by XHR Loader) that is loading this File.

Type:
XMLHttpRequest
Inherited from: Phaser.Loader.File#xhrLoader
Since: 3.0.0
Source: src/loader/File.js (Line 136)
Focus
Focus

Description:

The merged XHRSettings for this file.

Type:
Inherited from: Phaser.Loader.File#xhrSettings
Since: 3.0.0
Source: src/loader/File.js (Line 122)
Focus
Focus

Methods

addToCache()
Focus
Focus

Description:

Adds this file to its target cache upon successful loading and processing. This method is often overridden by specific file types.

Inherited from: Phaser.Loader.File#addToCache
Since: 3.7.0
Source: src/loader/File.js (Line 502)
Focus
Focus
destroy()
Focus
Focus

Description:

Destroy this File and any references it holds.

Inherited from: Phaser.Loader.File#destroy
Since: 3.7.0
Source: src/loader/File.js (Line 546)
Focus
Focus
hasCacheConflict()
Focus
Focus

Description:

Checks if a key matching the one used by this file exists in the target Cache or not. This is called automatically by the LoaderPlugin to decide if the file can be safely loaded or will conflict.

Returns:
Description:

true if adding this file will cause a conflict, otherwise false.

Type:
  • boolean
Inherited from: Phaser.Loader.File#hasCacheConflict
Since: 3.7.0
Source: src/loader/File.js (Line 487)
Focus
Focus
load()
Focus
Focus

Description:

Called by the Loader, starts the actual file downloading. During the load the methods onLoad, onError and onProgress are called, based on the XHR events. You shouldn't normally call this method directly, it's meant to be invoked by the Loader.

Inherited from: Phaser.Loader.File#load
Since: 3.0.0
Source: src/loader/File.js (Line 296)
Focus
Focus
onBase64Load(xhr)
Focus
Focus

Description:

Called by the XHRLoader if it was given a File with base64 data to load.

Parameters:

name type description
xhr XMLHttpRequest

The FakeXHR object containing the decoded base64 data.

Inherited from: Phaser.Loader.File#onBase64Load
Since: 3.80.0
Source: src/loader/File.js (Line 364)
Focus
Focus
onError(xhr, event)
Focus
Focus

Description:

Called if the file errors while loading, is sent a DOM ProgressEvent.

Parameters:

name type description
xhr XMLHttpRequest

The XMLHttpRequest that caused this onload event.

event ProgressEvent

The DOM ProgressEvent that resulted from this error.

Inherited from: Phaser.Loader.File#onError
Since: 3.0.0
Source: src/loader/File.js (Line 385)
Focus
Focus
onLoad(xhr, event)
Focus
Focus

Description:

Called when the file finishes loading, is sent a DOM ProgressEvent.

Parameters:

name type description
xhr XMLHttpRequest

The XMLHttpRequest that caused this onload event.

event ProgressEvent

The DOM ProgressEvent that resulted from this load.

Inherited from: Phaser.Loader.File#onLoad
Since: 3.0.0
Source: src/loader/File.js (Line 331)
Focus
Focus
onProcess()
Focus
Focus

Description:

Called automatically by Loader.nextFile. This method controls what extra work this File does with its loaded data.

Overrides: Phaser.Loader.File#onProcess
Since: 3.7.0
Focus
Focus
onProcessComplete()
Focus
Focus

Description:

Called when the File has completed processing. Checks on the state of its multifile, if set.

Inherited from: Phaser.Loader.File#onProcessComplete
Since: 3.7.0
Source: src/loader/File.js (Line 446)
Focus
Focus
onProcessError()
Focus
Focus

Description:

Called when the File has completed processing but it generated an error. Checks on the state of its multifile, if set.

Inherited from: Phaser.Loader.File#onProcessError
Since: 3.7.0
Source: src/loader/File.js (Line 465)
Focus
Focus
onProgress(event)
Focus
Focus

Description:

Called during the file load progress. Is sent a DOM ProgressEvent.

Parameters:

name type description
event ProgressEvent

The DOM ProgressEvent.

Inherited from: Phaser.Loader.File#onProgress
Since: 3.0.0
Source: src/loader/File.js (Line 410)
Focus
Focus
pendingDestroy()
Focus
Focus

Description:

Called once the file has been added to its cache and is now ready for deletion from the Loader. It will emit a filecomplete event from the LoaderPlugin.

Inherited from: Phaser.Loader.File#pendingDestroy
Since: 3.7.0
Source: src/loader/File.js (Line 517)
Focus
Focus
resetXHR()
Focus
Focus

Description:

Resets the XHRLoader instance this file is using.

Inherited from: Phaser.Loader.File#resetXHR
Since: 3.0.0
Source: src/loader/File.js (Line 280)
Focus
Focus