Accessed via FlxG.assets. The main interface for the asset system. By default, OpenFl's Asset system is used, which uses relative path strings to retrive assets, though you can completely avoid Openfl's asset system by setting custom methods to the following dynamic fields: getAssetUnsafe, loadAsset, exists, isLocal and list.

Common Uses

The initial reason for making customizable asset system was to allow for "hot-reloading", or testing new assets in your game without recompiling, with each change. Say, if you would like a debug feature where you load assets from source assets, rather than the assets copied over to your export folder, you could overwrite this system to do just that.

Other potential uses for this are modding, bypassing the manifest and loading resources from a remote location.

Quick Setup for "Hot-Reloading"

To simplify the process mentioned above, the FLX_CUSTOM_ASSETS_DIRECTORY flag was created. By adding -DFLX_CUSTOM_ASSETS_DIRECTORY="assets" to your lime build command it will automatically grab assets from your project root's assets folder rather than, the default "export/hl/bin/assets". This will only work with a single asset root folder with one asset library and will use the openfl asset system if the asset id starts with "flixel/" or tries to references a specific library using the format: "libName:asset/path/file.ext".

Available since

5.9.0

.

Constructor

new()

Variables

@:value(".mp3")finaldefaultSoundExtension:String = ".mp3"

Methods

dynamicexists(id:String, ?type:FlxAssetType):Bool

Whether a specific asset ID and type exists. Can be set to a custom function to avoid the existing asset system.

Parameters:

id

The ID or asset path for the asset

type

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

@:value({ useCache : true })getAsset(id:String, type:FlxAssetType, useCache:Bool = true, ?logStyle:LogStyle):Null<Any>

Calls getAssetUnsafe if the asset exists, otherwise logs that the asset is missing, via FlxG.log

Parameters:

id

The id of the asset, usually a path

type

The type of asset to look for, determines the type

useCache

Whether to allow use of the asset cache (if one exists)

logStyle

How to log, if the asset is not found. Uses LogStyle.ERROR by default

@:value({ useCache : true })dynamicgetAssetUnsafe(id:String, type:FlxAssetType, useCache:Bool = true):Null<Any>

Used by methods like getAsset, getBitmapData, getText, their "unsafe" counterparts and the like to get assets synchronously. Can be set to a custom function to avoid the existing asset system. Unlike its "safe" counterpart, there is no log on missing assets

Parameters:

id

The id of the asset, usually a path

type

The type of asset to look for, determines the type

useCache

Whether to allow use of the asset cache (if one exists)

Returns:

The asset, if found, otherwise null is returned

@:value({ useCache : false })inlinegetBitmapData(id:String, useCache:Bool = false, ?logStyle:LogStyle):BitmapData

Gets an instance of a bitmap, logs when the asset is not found

Parameters:

id

The ID or asset path for the bitmap

useCache

Whether to allow use of the asset cache (if one exists)

Returns:

A new BitmapData object

@:value({ useCache : false })inlinegetBitmapDataUnsafe(id:String, useCache:Bool = false):BitmapData

Gets an instance of a bitmap. Unlike its "safe" counterpart, there is no log on missing assets

Parameters:

id

The ID or asset path for the bitmap

useCache

Whether to allow use of the asset cache (if one exists)

Returns:

A new BitmapData object

@:value({ useCache : true })inlinegetBytes(id:String, useCache:Bool = true, ?logStyle:LogStyle):Bytes

Gets the contents of a binary asset, logs when the asset is not found

Note: The default asset system does not cache binary assets

Parameters:

id

The ID or asset path for the asset

useCache

Whether to allow use of the asset cache (if one exists)

logStyle

How to log, if the asset is not found. Uses LogStyle.ERROR by default

@:value({ useCache : true })inlinegetBytesUnsafe(id:String, useCache:Bool = true):Bytes

Gets the contents of a binary asset. Unlike its "safe" counterpart, there is no log on missing assets

Note: The default asset system does not cache binary assets

Parameters:

id

The ID or asset path for the asset

useCache

Whether to allow use of the asset cache (if one exists)

@:value({ useCache : true })inlinegetFont(id:String, useCache:Bool = true, ?logStyle:LogStyle):Font

Gets the contents of a font asset, logs when the asset is not found

Parameters:

id

The ID or asset path for the asset

useCache

Whether to allow use of the asset cache (if one exists)

logStyle

How to log, if the asset is not found. Uses LogStyle.ERROR by default

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

Gets the contents of a font asset. Unlike its "safe" counterpart, there is no log on missing assets

Parameters:

id

The ID or asset path for the asset

useCache

Whether to allow use of the asset cache

@:value({ useCache : true })inlinegetJson(id:String, useCache:Bool = true, ?logStyle:LogStyle):Null<Null<Dynamic>>

Gets the contents of a json-based asset, logs when the asset is not found

Note: The default asset system does not cache json assets

Parameters:

id

The ID or asset path for the asset

useCache

Whether to allow use of the asset cache (if one exists)

logStyle

How to log, if the asset is not found. Uses LogStyle.ERROR by default

@:value({ useCache : true })inlinegetJsonUnsafe(id:String, useCache:Bool = true):Null<Null<Dynamic>>

Gets the contents of a json-based asset. Unlike its "safe" counterpart, there is no log on missing assets

Note: The default asset system does not cache json assets

Parameters:

id

The ID or asset path for the asset

useCache

Whether to allow use of the asset cache (if one exists)

@:value({ useCache : true })inlinegetSound(id:String, useCache:Bool = true, ?logStyle:LogStyle):Sound

Gets an instance of a sound, logs when the asset is not found.

Note: If the FLX_DEFAULT_SOUND_EXT flag is enabled, you may omit the file extension

Parameters:

id

The ID or asset path for the sound

useCache

Whether to allow use of the asset cache (if one exists)

logStyle

How to log, if the asset is not found. Uses LogStyle.ERROR by default

Returns:

A new Sound object Note: Dos not return a FlxSound

@:value({ useCache : true })inlinegetSoundAddExt(id:String, useCache:Bool = true, ?logStyle:LogStyle):Sound

Gets an instance of a sound, logs when the asset is not found

Parameters:

id

The ID or asset path for the sound

useCache

Whether to allow use of the asset cache (if one exists)

logStyle

How to log, if the asset is not found. Uses LogStyle.ERROR by default

Returns:

A new Sound object Note: Dos not return a FlxSound

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

Gets an instance of a sound. Unlike its "safe" counterpart, there is no log on missing assets

Parameters:

id

The ID or asset path for the sound

useCache

Whether to allow use of the asset cache (if one exists)

Returns:

A new Sound object Note: Dos not return a FlxSound

@:value({ useCache : true })inlinegetText(id:String, useCache:Bool = true, ?logStyle:LogStyle):String

Gets the contents of a text-based asset, logs when the asset is not found

Note: The default asset system does not cache text assets

Parameters:

id

The ID or asset path for the asset

useCache

Whether to allow use of the asset cache (if one exists)

logStyle

How to log, if the asset is not found. Uses LogStyle.ERROR by default

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

Gets the contents of a text-based asset. Unlike its "safe" counterpart, there is no log on missing assets

Note: The default asset system does not cache text assets

Parameters:

id

The ID or asset path for the asset

useCache

Whether to allow use of the asset cache (if one exists)

@:value({ useCache : true })inlinegetXml(id:String, useCache:Bool = true, ?logStyle:LogStyle):Null<Null<Xml>>

Parses the contents of an xml-based asset into an Xml object, logs when the asset is not found

Note: The default asset system does not cache xml assets

Parameters:

id

The ID or asset path for the asset

useCache

Whether to allow use of the asset cache (if one exists)

logStyle

How to log, if the asset is not found. Uses LogStyle.ERROR by default

@:value({ useCache : true })inlinegetXmlUnsafe(id:String, useCache:Bool = true):Null<Null<Xml>>

Parses the contents of an xml-based asset into an Xml object. Unlike its "safe" counterpart, there is no log on missing assets

Note: The default asset system does not cache xml assets

Parameters:

id

The ID or asset path for the asset

useCache

Whether to allow use of the asset cache (if one exists)

@:value({ useCache : true })dynamicisLocal(id:String, ?type:FlxAssetType, useCache:Bool = true):Bool

Returns whether an asset is "local", and therefore can be loaded synchronously, or with the getAsset method, otherwise the loadAsset method should be used. Can be set to a custom function to avoid the existing asset system.

Parameters:

id

The ID or asset path for the asset

type

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

useCache

Whether to allow use of the asset cache (if one exists)

Returns:

Whether the asset is local

dynamiclist(?type:FlxAssetType):Array<String>

Returns a list of all assets (by type). Can be set to a custom function to avoid the existing asset system.

Parameters:

type

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

Returns:

An array of asset ID values

@:value({ useCache : true })dynamicloadAsset(id:String, type:FlxAssetType, useCache:Bool = true):Future<Any>

Used by methods like loadBitmapData, loadText and the like to get assets asynchronously. Can be set to a custom function to avoid the existing asset system.

Parameters:

id

The id of the asset, usually a path

type

The type of asset to look for, determines the type

useCache

Whether to allow use of the asset cache (if one exists)

@:value({ useCache : false })inlineloadBitmapData(id:String, useCache:Bool = false):Future<BitmapData>

Loads a bitmap asset asynchronously

Parameters:

id

The ID or asset path for the asset

useCache

Whether to allow use of the asset cache (if one exists)

Returns:

Returns a Future which allows listeners to be added via methods like onComplete

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

Loads a binary asset asynchronously

Note: The default asset system does not cache binary assets

Parameters:

id

The ID or asset path for the asset

useCache

Whether to allow use of the asset cache (if one exists)

Returns:

Returns a Future which allows listeners to be added via methods like onComplete

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

Loads a font asset asynchronously

Parameters:

id

The ID or asset path for the asset

useCache

Whether to allow use of the asset cache (if one exists)

Returns:

Returns a Future which allows listeners to be added via methods like onComplete

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

Loads a json asset asynchronously

Note: The default asset system does not cache json assets

Parameters:

id

The ID or asset path for the asset

useCache

Whether to allow use of the asset cache (if one exists)

Returns:

Returns a Future which allows listeners to be added via methods like onComplete

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

Loads a sound asset asynchronously

Parameters:

id

The ID or asset path for the asset

useCache

Whether to allow use of the asset cache (if one exists)

Returns:

Returns a Future which allows listeners to be added via methods like onComplete

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

Loads a text asset asynchronously

Note: The default asset system does not cache text assets

Parameters:

id

The ID or asset path for the asset

useCache

Whether to allow use of the asset cache (if one exists)

Returns:

Returns a Future which allows listeners to be added via methods like onComplete

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

Loads an xml asset asynchronously

Note: The default asset system does not cache xml assets

Parameters:

id

The ID or asset path for the asset

useCache

Whether to allow use of the asset cache (if one exists)

Returns:

Returns a Future which allows listeners to be added via methods like onComplete

inlineparseJson(jsonText:String):Dynamic

Parses a json string, creates and returns a struct

inlineparseXml(xmlText:String):Xml

Parses an xml string, creates and returns an Xml object