class openfl.Assets
Available on all platforms
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
Class Fields
static function addEventListener(type:String, listener:Dynamic, ?useCapture:Bool = false, ?priority:Int = 0, ?useWeakReference:Bool = false):Void
static function exists(id:String, ?type:AssetType = null):Bool
Returns whether a specific asset exists
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 |
static function getBitmapData(id:String, ?useCache:Bool = true):BitmapData
Gets an instance of an embedded bitmap @usage var bitmap = new Bitmap (Assets.getBitmapData ("image.png"));
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 |
static function getBytes(id:String):ByteArray
Gets an instance of an embedded binary asset @usage var bytes = Assets.getBytes ("file.zip");
id | The ID or asset path for the asset |
returns | A new ByteArray object |
static function getFont(id:String, ?useCache:Bool = true):Font
Gets an instance of an embedded font @usage var fontName = Assets.getFont ("font.ttf").fontName;
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 |
static function getMovieClip(id:String):MovieClip
Gets an instance of an included MovieClip @usage var movieClip = Assets.getMovieClip ("library:BouncingBall");
id | The ID for the MovieClip |
returns | A new MovieClip object |
static function getMusic(id:String, ?useCache:Bool = true):Sound
Gets an instance of an embedded streaming sound @usage var sound = Assets.getMusic ("sound.ogg");
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 |
static function getPath(id:String):String
Gets the file path (if available) for an asset @usage var path = Assets.getPath ("file.txt");
id | The ID or asset path for the asset |
returns | The path to the asset, or null if it does not exist |
static function getSound(id:String, ?useCache:Bool = true):Sound
Gets an instance of an embedded sound @usage var sound = Assets.getSound ("sound.wav");
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 |
static function getText(id:String):String
Gets an instance of an embedded text asset @usage var text = Assets.getText ("text.txt");
id | The ID or asset path for the asset |
returns | A new String object |
static function isLocal(id:String, ?type:AssetType = null, ?useCache:Bool = true):Bool
Returns whether an asset is "local", and therefore can be loaded synchronously
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 |
static function list(?type:AssetType = null):Array<String>
Returns a list of all embedded assets (by type)
type | The asset type to match, or null to match any type |
returns | An array of asset ID values |
static function loadBitmapData(id:String, ?useCache:Bool = true, ?handler:BitmapData ->Void = null):Future<BitmapData>
Loads an included bitmap asset asynchronously @usage Asset.loadBitmapData ("image.png").onComplete (handleImage);
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 |
static function loadBytes(id:String, ?handler:ByteArray ->Void = null):Future<ByteArray>
Loads an included byte asset asynchronously @usage Asset.loadBytes ("file.zip").onComplete (handleBytes);
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 |
static function loadFont(id:String, ?useCache:Bool = true, ?handler:Font ->Void = null):Future<Font>
Loads an included font asset asynchronously @usage Asset.loadFont ("font.ttf").onComplete (handleFont);
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 |
static function loadLibrary(name:String, ?handler:LimeAssetLibrary ->Void = null):Future<LimeAssetLibrary>
Load an included AssetLibrary
name | The name of the AssetLibrary to load |
handler | (Deprecated) A callback function when the load is completed |
returns | Returns a Future |
static function loadMovieClip(id:String, ?handler:MovieClip ->Void = null):Future<MovieClip>
Loads an included MovieClip asset asynchronously @usage Asset.loadMovieClip ("library:BouncingBall").onComplete (handleMovieClip);
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 |
static function loadMusic(id:String, ?useCache:Bool = true, ?handler:Sound ->Void = null):Future<Sound>
Loads an included music asset asynchronously @usage Asset.loadMusic ("music.ogg").onComplete (handleMusic);
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 |
static function loadSound(id:String, ?useCache:Bool = true, ?handler:Sound ->Void = null):Future<Sound>
Loads an included sound asset asynchronously @usage Asset.loadSound ("sound.wav").onComplete (handleSound);
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 |
static function loadText(id:String, ?handler:String ->Void = null):Future<String>
Loads an included text asset asynchronously @usage Asset.loadText ("text.txt").onComplete (handleString);
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 |
static function registerLibrary(name:String, library:AssetLibrary):Void
Registers a new AssetLibrary with the Assets class
name | The name (prefix) to use for the library |
library | An AssetLibrary instance to register |