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
Static methods
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.
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
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
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
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