phaser - v4.0.0-rc.4
    Preparing search index...

    A single Script File suitable for loading by the Loader.

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

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

    Hierarchy (View Summary)

    Index

    Constructors

    • Parameters

      • loader: LoaderPlugin

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

      • key: string | ScriptFileConfig

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

      • Optionalurl: string

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

      • Optionaltype: string

        The script type. Should be either 'script' for classic JavaScript, or 'module' if the file contains an exported module. Default 'script'.

      • OptionalxhrSettings: XHRSettingsObject

        Extra XHR Settings specifically for this file.

      Returns ScriptFile

    Properties

    base64: boolean

    Does this File contain a data URI?

    bytesLoaded: number

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

    bytesTotal: number

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

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

    config: any

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

    crossOrigin: string

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

    data: any

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

    key: string

    Unique cache key (unique within its file type)

    linkFile: File

    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.

    loader: LoaderPlugin

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

    multiFile: MultiFile

    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.

    percentComplete: number

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

    retryAttempts: number

    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.

    src: string

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

    state: number

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

    type: string

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

    url: string | object

    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.

    xhrLoader: XMLHttpRequest

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

    xhrSettings: XHRSettingsObject

    The merged XHRSettings for this file.

    Methods

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

      Returns void

    • 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 boolean

    • 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.

      Returns void

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

      Parameters

      • xhr: XMLHttpRequest

        The FakeXHR object containing the decoded base64 data.

      Returns void

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

      Parameters

      • xhr: XMLHttpRequest

        The XMLHttpRequest that caused this onload event.

      • event: ProgressEvent

        The DOM ProgressEvent that resulted from this error.

      Returns void

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

      Parameters

      • xhr: XMLHttpRequest

        The XMLHttpRequest that caused this onload event.

      • event: ProgressEvent

        The DOM ProgressEvent that resulted from this load.

      Returns void

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

      Returns void

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

      Returns void

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

      Parameters

      • event: ProgressEvent

        The DOM ProgressEvent.

      Returns void

    • 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.

      Returns void

    • Links this File with another, so they depend upon each other for loading and processing.

      Parameters

      • fileB: File

        The file to link to this one.

      Returns void

    • Static method for creating object URL using URL API and setting it as image 'src' attribute. If URL API is not supported (usually on old browsers) it falls back to creating Base64 encoded url using FileReader.

      Parameters

      • image: HTMLImageElement

        Image object which 'src' attribute should be set to object URL.

      • blob: Blob

        A Blob object to create an object URL for.

      • defaultType: string

        Default mime type used if blob type is not available.

      Returns void