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

staticgetLibrary(name:String):LimeAssetLibrary

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

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

statichasEventListener(type:String):Bool

statichasLibrary(name:String):Bool

@:value({ instance : null })staticinitBinding(className:String, ?instance:Dynamic):Void

Connects a user-defined class to a related asset class.

This method call is added to the beginning of user-defined class constructors when the @:bind meta-data is used. This allows insertion of related asset resources in compatible super classes, such as openfl.display.MovieClip.

Parameters:

className

The registered class name of the asset constructor

instance

The current class instance to be bound (default is null)

Returns:

Whether asset binding was successful

@: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({ useCache : true })staticloadBitmapData(id:String, useCache:Bool = true):Future<BitmapData>

Loads an included bitmap asset asynchronously @usage Assets.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)

Returns:

Returns a Future

staticloadBytes(id:String):Future<ByteArray>

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

Parameters:

id

The ID or asset path for the asset

Returns:

Returns a Future

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

Loads an included font asset asynchronously @usage Assets.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)

Returns:

Returns a Future

staticloadLibrary(name:String):Future<AssetLibrary>

Load an included AssetLibrary

Parameters:

name

The name of the AssetLibrary to load

Returns:

Returns a Future

staticloadMovieClip(id:String):Future<MovieClip>

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

Parameters:

id

The ID for the asset

useCache

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

Returns:

Returns a Future

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

Loads an included music asset asynchronously @usage Assets.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)

Returns:

Returns a Future

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

Loads an included sound asset asynchronously @usage Assets.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)

Returns:

Returns a Future

staticloadText(id:String):Future<String>

Loads an included text asset asynchronously @usage Assets.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)

Returns:

Returns a Future

staticregisterBinding(className:String, library:AssetLibrary):Void

Registers an AssetLibrary binding for use with @:bind or Assets.bind

Parameters:

className

The class name to use for the binding

method

The AssetLibrary responsible for the binding

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

staticunloadLibrary(name:String):Void

staticunregisterBinding(className:String, library:AssetLibrary):Void

Unregisters an AssetLibrary binding for use with @:bind or Assets.bind

Parameters:

className

The class name to use for the binding

method

The AssetLibrary responsible for the binding