Skip to main content
The Assets class is a wrapper around openfl.utils.Assets that provides safe access to asset loading functions with Funkin-specific caching.

Overview

The Assets class provides methods for loading:
  • Text files and binary data
  • Images and bitmap data
  • Sound effects and music
  • Asset libraries
All methods are static and can be called directly without instantiation.

Properties

openfl.utils.IAssetCache
The OpenFL assets cache. Access directly for cache management.
Example:

Methods

getPath()

Returns the file system path for an asset.
String
required
The asset path relative to the assets folder.
Returns: The absolute path to the asset on the file system. Example:

Text and Binary Assets

getText()

Loads text from an asset synchronously.
String
required
The asset path to load from.
Returns: The text contents of the file.
Synchronous loading may cause stutters. Use loadText() for asynchronous loading when possible.
Example:

loadText()

Loads text from an asset asynchronously.
String
required
The asset path to load from.
Returns: A Future that resolves with the text contents. Example:

getBytes()

Loads binary data from an asset synchronously.
String
required
The asset path to load from.
Returns: The byte contents of the file. Example:

loadBytes()

Loads binary data from an asset asynchronously.
String
required
The asset path to load from.
Returns: A Future that resolves with the byte contents.

Image Assets

getBitmapData()

Loads a bitmap image synchronously.
String
required
The asset path to load from.
Bool
default:"true"
Whether to use the asset cache. Set to false to force a fresh load.
Returns: The loaded BitmapData.
Synchronous loading may cause stutters. Use loadBitmapData() for asynchronous loading when possible.
Example:

loadBitmapData()

Loads a bitmap image asynchronously.
String
required
The asset path to load from.
Returns: A Future that resolves with the loaded BitmapData. Example:

Audio Assets

getSound()

Loads a sound file synchronously.
String
required
The asset path to load from.
Returns: The loaded Sound object.
Synchronous loading may cause stutters. Use loadSound() for asynchronous loading when possible.
Example:

loadSound()

Loads a sound file asynchronously.
String
required
The asset path to load from.
Returns: A Future that resolves with the loaded Sound. Example:

getMusic()

Loads a music file synchronously with optimizations for long-duration audio.
String
required
The asset path to load from.
Returns: The loaded Sound object optimized for music. Example:

loadMusic()

Loads a music file asynchronously with optimizations for long-duration audio.
String
required
The asset path to load from.
Returns: A Future that resolves with the loaded music Sound. Example:

Asset Library Management

exists()

Checks whether an asset exists.
String
required
The asset path to check.
AssetType
The asset type to check (IMAGE, SOUND, TEXT, etc.).
Returns: True if the asset exists. Example:

list()

Retrieves a list of all assets of a given type.
AssetType
The asset type to list. If omitted, lists all assets.
Returns: Array of asset paths. Example:

hasLibrary()

Checks if an asset library exists.
String
required
The library name to check.
Returns: True if the library exists.

getLibrary()

Retrieves an asset library by name.
String
required
The name of the library to get.
Returns: The AssetLibrary object.

loadLibrary()

Loads an asset library asynchronously.
String
required
The name of the library to load.
Returns: A Future that resolves with the AssetLibrary. Example:

Best Practices

Use Asynchronous Loading

Prefer async methods to avoid frame stutters:

Check Asset Existence

Validate assets exist before loading:

Manage Cache

Manually manage cache for memory-intensive assets:

Example: Asset Preloader

See Also