# AssetListLoader

Class · extends [`EventHandler`](https://api.playcanvas.com/engine/classes/EventHandler.md) · category: Asset

Source: https://github.com/playcanvas/engine/blob/970d89f6d3bc6667f4e1f88153abd6e7e82ed52c/src/framework/asset/asset-list-loader.js#L30

An AssetListLoader loads a group of assets together and reports once when every one of them has
loaded or failed. Pass it [Asset](https://api.playcanvas.com/engine/classes/Asset.md) instances or asset ids. Assets not yet in the
[AssetRegistry](https://api.playcanvas.com/engine/classes/AssetRegistry.md) are added, and ids that the registry does not know yet are waited for until
a matching asset is registered. Call [load](https://api.playcanvas.com/engine/classes/AssetListLoader.md#load) to start loading and [ready](https://api.playcanvas.com/engine/classes/AssetListLoader.md#ready) to be told
when the list is complete without starting anything.

**Example**

```ts
const assets = [
    new Asset('model', 'container', { url: 'http://example.com/asset.glb' }),
    new Asset('styling', 'css', { url: 'http://example.com/asset.css' })
];
const assetListLoader = new AssetListLoader(assets, app.assets);
assetListLoader.load((err, failed) => {
    if (err) {
        console.error(`${failed.length} assets failed to load`);
    } else {
        console.log(`${assets.length} assets loaded`);
    }
});
```

## Constructors

### constructor

```ts
new AssetListLoader(assetList: number[] | Asset<string>[], assetRegistry: AssetRegistry)
```

Create a new AssetListLoader using a list of assets to load and the asset registry used to
load and manage them.

**Parameters**

- `assetList` (`number[] |` [`Asset`](https://api.playcanvas.com/engine/classes/Asset.md)`<string>[]`): An array of [Asset](https://api.playcanvas.com/engine/classes/Asset.md) objects to load or an array
  of Asset IDs to load.
- `assetRegistry` ([`AssetRegistry`](https://api.playcanvas.com/engine/classes/AssetRegistry.md)): The application's asset registry.

**Example**

```ts
const assetListLoader = new AssetListLoader([
    new Asset("texture1", "texture", { url: 'http://example.com/my/assets/here/texture1.png' }),
    new Asset("texture2", "texture", { url: 'http://example.com/my/assets/here/texture2.png' })
], app.assets);
```

## Methods

### destroy

```ts
destroy(): void
```

Removes all references to this asset list loader.

### load

```ts
load(done: Function, scope?: any): void
```

Start loading asset list and call `done()` when all assets have loaded or failed to load.

**Parameters**

- `done` (`Function`): Callback called when all assets in the list are loaded. Passed
  `(err, failed)` where `err` is `undefined` if no errors are encountered and failed contains
  an array of assets that failed to load.
- `scope` (`any`, optional): Scope to use when calling callback.

### ready

```ts
ready(done: Function, scope?: any): void
```

Sets a callback which will be called when all assets in the list have been loaded.

**Parameters**

- `done` (`Function`): Callback called when all assets in the list are loaded.
- `scope` (`any`, optional): Scope to use when calling callback.

## Inherited from [EventHandler](https://api.playcanvas.com/engine/classes/EventHandler.md)

- `fire(name: string, arg1?: any, arg2?: any, arg3?: any, arg4?: any, arg5?: any, arg6?: any, arg7?: any, arg8?: any): EventHandler`
- `hasEvent(name: string): boolean`
- `off(name?: string, callback?: HandleEventCallback, scope?: any): EventHandler`
- `on(name: string, callback: HandleEventCallback, scope?: any): EventHandle`
- `once(name: string, callback: HandleEventCallback, scope?: any): EventHandle`
