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 OpenFL command-line tools, based on the contents of the *.xml 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. You can customize the preloader by extending the NMEPreloader class, and specifying a custom preloader using in the project file.

Static variables

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

Static methods

@:value({ useWeakReference : false, priority : 0, useCapture : false })staticaddEventListener(type:String, listener:Dynamic, useCapture:Bool = false, priority:Int = 0, useWeakReference:Bool = false):Void

staticdispatchEvent(event:Event):Bool

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

Returns whether a specific asset exists

Parameters:

id

The ID or asset path for the asset

type

The asset type to match, or null to match any type

Returns:

Whether the requested asset ID and type exists

@:value({ useCache : true })staticgetBitmapData(id:String, useCache:Bool = true):BitmapData

Gets an instance of an embedded bitmap @usage var bitmap = new Bitmap (Assets.getBitmapData ("image.png"));

Parameters:

id

The ID or asset path for the bitmap

useCache

(Optional) Whether to allow use of the asset cache (Default: true)

Returns:

A new BitmapData object

staticgetBytes(id:String):ByteArray

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

Parameters:

id

The ID or asset path for the asset

Returns:

A new ByteArray 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

useCache

(Optional) Whether to allow use of the asset cache (Default: true)

Returns:

A new Font object

staticgetMovieClip(id:String):MovieClip

Gets an instance of an included MovieClip @usage var movieClip = Assets.getMovieClip ("library:BouncingBall");

Parameters:

id

The ID for the MovieClip

Returns:

A new MovieClip object

@:value({ useCache : true })staticgetMusic(id:String, useCache:Bool = true):Sound

Gets an instance of an embedded streaming sound @usage var sound = Assets.getMusic ("sound.ogg");

Parameters:

id

The ID or asset path for the audio stream

useCache

(Optional) Whether to allow use of the asset cache (Default: true)

Returns:

A new Sound object

staticgetPath(id:String):String

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

Parameters:

id

The ID or asset path for the asset

Returns:

The path to the asset, or null if it does not exist

@:value({ useCache : true })staticgetSound(id:String, useCache:Bool = true):Sound

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

Parameters:

id

The ID or asset path for the sound

useCache

(Optional) Whether to allow use of the asset cache (Default: true)

Returns:

A new Sound object

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 asset

Returns:

A new String object

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

Returns whether an asset is "local", and therefore can be loaded synchronously

Parameters:

id

The ID or asset path for the asset

type

The asset type to match, or null to match any type

useCache

(Optional) Whether to allow use of the asset cache (Default: true)

Returns:

Whether the asset is local

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

Returns a list of all embedded assets (by type)

Parameters:

type

The asset type to match, or null to match any type

Returns:

An array of asset ID values

@:value({ handler : null, useCache : true })staticloadBitmapData(id:String, useCache:Bool = true, ?handler:BitmapData‑>Void):Future<BitmapData>

Loads an included bitmap asset asynchronously @usage Asset.loadBitmapData ("image.png").onComplete (handleImage);

Parameters:

id

The ID or asset path for the asset

useCache

(Optional) Whether to allow use of the asset cache (Default: true)

handler

(Deprecated) A callback function when the load is completed

Returns:

Returns a Future

@:value({ handler : null })staticloadBytes(id:String, ?handler:ByteArray‑>Void):Future<ByteArray>

Loads an included byte asset asynchronously @usage Asset.loadBytes ("file.zip").onComplete (handleBytes);

Parameters:

id

The ID or asset path for the asset

useCache

(Optional) Whether to allow use of the asset cache (Default: true)

handler

(Deprecated) A callback function when the load is completed

Returns:

Returns a Future

@:value({ handler : null, useCache : true })staticloadFont(id:String, useCache:Bool = true, ?handler:Font‑>Void):Future<Font>

Loads an included font asset asynchronously @usage Asset.loadFont ("font.ttf").onComplete (handleFont);

Parameters:

id

The ID or asset path for the asset

useCache

(Optional) Whether to allow use of the asset cache (Default: true)

handler

(Deprecated) A callback function when the load is completed

Returns:

Returns a Future

@:value({ handler : null })staticloadLibrary(name:String, ?handler:LimeAssetLibrary‑>Void):Future<LimeAssetLibrary>

Load an included AssetLibrary

Parameters:

name

The name of the AssetLibrary to load

handler

(Deprecated) A callback function when the load is completed

Returns:

Returns a Future

@:value({ handler : null })staticloadMovieClip(id:String, ?handler:MovieClip‑>Void):Future<MovieClip>

Loads an included MovieClip asset asynchronously @usage Asset.loadMovieClip ("library:BouncingBall").onComplete (handleMovieClip);

Parameters:

id

The ID for the asset

useCache

(Optional) Whether to allow use of the asset cache (Default: true)

handler

(Deprecated) A callback function when the load is completed

Returns:

Returns a Future

@:value({ handler : null, useCache : true })staticloadMusic(id:String, useCache:Bool = true, ?handler:Sound‑>Void):Future<Sound>

Loads an included music asset asynchronously @usage Asset.loadMusic ("music.ogg").onComplete (handleMusic);

Parameters:

id

The ID or asset path for the asset

useCache

(Optional) Whether to allow use of the asset cache (Default: true)

handler

(Deprecated) A callback function when the load is completed

Returns:

Returns a Future

@:value({ handler : null, useCache : true })staticloadSound(id:String, useCache:Bool = true, ?handler:Sound‑>Void):Future<Sound>

Loads an included sound asset asynchronously @usage Asset.loadSound ("sound.wav").onComplete (handleSound);

Parameters:

id

The ID or asset path for the asset

useCache

(Optional) Whether to allow use of the asset cache (Default: true)

handler

(Deprecated) A callback function when the load is completed

Returns:

Returns a Future

@:value({ handler : null })staticloadText(id:String, ?handler:String‑>Void):Future<String>

Loads an included text asset asynchronously @usage Asset.loadText ("text.txt").onComplete (handleString);

Parameters:

id

The ID or asset path for the asset

useCache

(Optional) Whether to allow use of the asset cache (Default: true)

handler

(Deprecated) A callback function when the load is completed

Returns:

Returns a Future

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

Registers a new AssetLibrary with the Assets class

Parameters:

name

The name (prefix) to use for the library

library

An AssetLibrary instance to register

@:value({ capture : false })staticremoveEventListener(type:String, listener:Dynamic, capture:Bool = false):Void