The Assets class provides a cross-platform interface to access embedded images, fonts, sounds and other resource files.

The contents are populated automatically when an application is compiled using the Lime command-line tools, based on the contents of the project file.

For most platforms, the assets are included in the same directory or package as the application, and the paths are handled automatically. For web content, the assets are preloaded before the start of the rest of the application.

Static variables

@:value(new AssetCache())staticcache:AssetCache = new AssetCache()

@:value(new Event<Void>())staticonChange:_Event_Void_Void<() ‑> Void> = new Event<Void>()

Static methods

@:value({ type : null })staticexists(id:String, ?type:AssetType):Bool

staticgetAsset(id:String, type:AssetType, useCache:Bool):Dynamic

Gets an instance of a cached or embedded asset @usage var sound = Assets.getAsset("sound.wav", SOUND);

Parameters:

id

The ID or asset path for the asset

Returns:

An Asset object, or null.

@:value({ useCache : true })staticgetAudioBuffer(id:String, useCache:Bool = true):AudioBuffer

Gets an instance of an embedded sound @usage var sound = Assets.getAudioBuffer ("sound.wav");

Parameters:

id

The ID or asset path for the sound

Returns:

A new Sound object

staticgetBytes(id:String):Bytes

Gets an instance of an embedded binary asset @usage var bytes = Assets.getBytes("file.zip");

Parameters:

id

The ID or asset path for the file

Returns:

A new Bytes object

@:value({ useCache : true })staticgetFont(id:String, useCache:Bool = true):Font

Gets an instance of an embedded font @usage var fontName = Assets.getFont("font.ttf").fontName;

Parameters:

id

The ID or asset path for the font

Returns:

A new Font object

@:value({ useCache : true })staticgetImage(id:String, useCache:Bool = true):Image

Gets an instance of an embedded bitmap.

Note: This method may behave differently, depending on the target platform. On targets that can quickly create a new image synchronously, every call to Assets.getImage() with the same ID will return a new Image instance. However, on other targets where creating images synchronously is unacceptably slow, or where images may not be created synchronously and must be created asynchronously, every call to Assets.getImage() with the same ID may return a single, shared Image instance.

With that in mind, modifying or disposing the contents of the Image returned by Assets.getImage() may affect the results of future calls to Assets.getImage() on some targets. To access an Image instance that may be modified without affecting future calls to Assets.getImage(), call the Image instance's clone()` method to manually create a copy.

@usage var bitmap = new Bitmap(Assets.getBitmapData("image.jpg"));

Parameters:

id

The ID or asset path for the bitmap

useCache

(Optional) Whether to use BitmapData from the cache(Default: true)

Returns:

A new BitmapData object

staticgetLibrary(name:String):AssetLibrary

staticgetPath(id:String):String

Gets the file path (if available) for an asset @usage var path = Assets.getPath("image.jpg");

Parameters:

id

The ID or asset path for the asset

Returns:

The path to the asset (or null)

staticgetText(id:String):String

Gets an instance of an embedded text asset @usage var text = Assets.getText("text.txt");

Parameters:

id

The ID or asset path for the file

Returns:

A new String object

statichasLibrary(name:String):Bool

@:value({ useCache : true, type : null })staticisLocal(id:String, ?type:AssetType, useCache:Bool = true):Bool

@:value({ type : null })staticlist(?type:AssetType):Array<String>

staticloadAsset(id:String, type:AssetType, useCache:Bool):Future<Dynamic>

@:value({ useCache : true })staticloadAudioBuffer(id:String, useCache:Bool = true):Future<AudioBuffer>

staticloadBytes(id:String):Future<Bytes>

@:value({ useCache : true })staticloadFont(id:String, useCache:Bool = true):Future<Font>

@:value({ useCache : true })staticloadImage(id:String, useCache:Bool = true):Future<Image>

staticloadLibrary(id:String):Future<AssetLibrary>

staticloadText(id:String):Future<String>

staticregisterLibrary(name:String, library:AssetLibrary):Void

@:value({ unload : true })staticremoveLibrary(name:String, unload:Bool = true):Void

staticunloadLibrary(name:String):Void