[name]

A low level class for loading resources with XMLHttpRequest, used internaly by most loaders. It can also be used directly to load any file type that does not have a loader.

Example

[example:webgl_loader_msgpack WebGL / loader / msgpack]
[example:webgl_morphtargets_human WebGL / morphtargets / human]
var loader = new THREE.FileLoader(); //load a text file a output the result to the console loader.load( // resource URL 'example.txt', // Function when resource is loaded function ( data ) { // output the text to the console console.log( data ) }, // Function called when download progresses function ( xhr ) { console.log( (xhr.loaded / xhr.total * 100) + '% loaded' ); }, // Function called when download errors function ( xhr ) { console.error( 'An error happened' ); } );

Constructor

[name]( [page:LoadingManager manager] )

[page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use. Default is [page:DefaultLoadingManager].

Properties

[property:Cache cache]

A reference to [page:Cache Cache] that hold the response from each request made through this loader, so each file is requested once.

Note:The cache must be enabled using THREE.Cache.enabled = true. This is a global property and only needs to be set once to be used by all loaders that use FileLoader internally.

[property:LoadingManager manager]

The [page:LoadingManager loadingManager] the loader is using. Default is [page:DefaultLoadingManager].

[property:String mimeType]

The expected [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types mimeType]. See [page:.setMimeType]. Default is *undefined*.

[property:String path]

The base path from which files will be loaded. See [page:.setPath]. Default is *undefined*.

[property:String responseType]

The expected response type. See [page:.setResponseType]. Default is *undefined*.

[property:String withCredentials]

Whether the XMLHttpRequest uses credentials - see [page:.setWithCredentials]. Default is *undefined*.

Methods

[method:null load]( [page:String url], [page:Function onLoad], [page:Function onProgress], [page:Function onError] )

[page:String url] — the path or URL to the file. This can also be a [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].
[page:Function onLoad] — Will be called when loading completes. The argument will be the loaded response.
[page:Function onProgress] — Will be called while load progresses. The argument will be the XMLHttpRequest instance, which contains .[page:Integer total] and .[page:Integer loaded] bytes.
[page:Function onError] — Will be called if an error occurs.

Load the URL and pass the response to the onLoad function.

[method:FileLoader setMimeType]( [page:String mimeType] )

Set the expected [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types mimeType] of the file being loaded. Note that in many cases this will be determined automatically, so by default it is *undefined*.

[method:FileLoader setPath]( [page:String path] )

Set the base path or URL from which to load files. This can be useful if you are loading many models from the same directory.

[method:FileLoader setResponseType]( [page:String responseType] )

[page:String responseType] — Default is '' (empty string).

Change the response type. Valid values are:
[page:String text], empty string (default), or any other value. Any file type, returns the unprocessed file data.
[page:String arraybuffer] - loads the data into a [link:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer ArrayBuffer] and returns that.
[page:String blob] - returns the data as a [link:https://developer.mozilla.org/en/docs/Web/API/Blob Blob].
[page:String document] - parse the file using the [link:https://developer.mozilla.org/en-US/docs/Web/API/DOMParser DOMParser].
[page:String json] - parse the file using [link:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse JSON.parse].

[method:FileLoader setWithCredentials]( [page:Boolean value] )

Whether the XMLHttpRequest uses credentials such as cookies, authorization headers or TLS client certificates. See [link:https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials XMLHttpRequest.withCredentials].
Note that this has no effect if you are loading files locally or from the same domain.

Source

[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]