class openfl.Assets
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 file |
| type | The type of assets AssetType.BINARY | AssetType.FONT | AssetType.IMAGE | AssetType.MOVIE_CLIP | AssetType.MUSIC | AssetType.SOUND | AssetType.TEMPLATE | AssetType.TEXT |
| returns | TRUE if an asset with a given id, and type exists FALSE otherwise |
static function getBitmapData(id:String, ?useCache:Bool = true): BitmapData
Gets an instance of an embedded bitmap @usage var bitmap = new Bitmap(Assets.getBitmapData("image.jpg"));
| 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 |
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 file |
| 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 |
| returns | A new Font object |
static function getMovieClip(id:String): MovieClip
Gets an instance of a library MovieClip @usage var movieClip = Assets.getMovieClip("library:BouncingBall");
| id | The library and ID for the MovieClip |
| returns | A new Sound 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 music track |
| 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("image.jpg");
| id | The ID or asset path for the asset |
| returns | The path to the asset (or null) |
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 |
| 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 file |
| returns | A new String object |
static function isLocal(id:String, ?type:AssetType = null, ?useCache:Bool = true): Bool
Returns whether an asset with a given id and "AssetType" exists within the cache or Asset Library
| id | The ID or asset path for the file |
| type | The type of assets AssetType.BINARY | AssetType.FONT | AssetType.IMAGE | AssetType.MOVIE_CLIP | AssetType.MUSIC | AssetType.SOUND | AssetType.TEMPLATE | AssetType.TEXT |
| useCache | Whether or not to use the cache. if FALSE this function will search for the asset in any known library |
| returns | whether or not an asset with the given id exists within the asset cache or any asset library; |
static function list(?type:AssetType = null): Array<String>
Returns an array of embeded assets
| type | The type of assets to include AssetType.BINARY | AssetType.FONT | AssetType.IMAGE | AssetType.MOVIE_CLIP | AssetType.MUSIC | AssetType.SOUND | AssetType.TEMPLATE | AssetType.TEXT |
| returns | an Array of embeded assets |
static function loadBitmapData(id:String, handler:BitmapData ->Void?useCache:Bool = true): Void
Asynchronously loads an instance of an embeded bitmap @usage Asset.loadBitmapData("MyReallyBigPic.jpg", function(_loadedBitmapData):Void{
var myReallyBigBitmap = new Bitmap(_loadedBitmapData);
});
| id | The ID or asset path for the file |
| handler | a funtion to handle the loaded BitmapData |
| useCache | whether or not to add / retrieve the asset from the cache |
static function loadBytes(id:String, handler:ByteArray ->Void): Void
Asynchronously loads an instance of an embedded binary file @usage Asset.loadBytes("MyReallyBigBin.bin", function(_loadedByteArray):Void{
myParserFunction(_loadedByteArray)
});
| id | The ID or asset path for the file |
| handler | a funtion to handle the loaded ByteArray |
| useCache | whether or not to add / retrieve the asset from the cache |
static function loadFont(id:String, handler:Font ->Void?useCache:Bool = true): Void
Asynchronously loads an instance of an embedded font @usage Asset.loadFont("MyReallyLongSong.ttf", function(_loadedFont):Void{
myTextFortmat.font = _loadedFont.fontName;
});
| id | The ID or asset path for the file |
| handler | a funtion to handle the loaded font |
| useCache | whether or not to add / retrieve the asset from the cache |
static function loadLibrary(name:String, handler:LimeAssetLibrary ->Void): Void
Loads an Asset Library with a given Name
| name | the name of the library to load |
| handler | the function to handle the loaded AssetLibrary |
static function loadMovieClip(id:String, handler:MovieClip ->Void): Void
Asynchronously loads an instance of a MovieClip from a library @usage Asset.loadMovieClip("libary:MovieClip", function(_loadedMovieClip):Void{
sprite.addChild(_loadedMovieClip);
});
| id | The ID or asset path for the file |
| handler | a funtion to handle the loaded movieclip |
| useCache | whether or not to add / retrieve the asset from the cache |
static function loadMusic(id:String, handler:Sound ->Void?useCache:Bool = true): Void
Asynchronously loads an instance of an embedded streaming sound @usage Asset.loadMusic("MyReallyLongSong.ogg", function(_loadedSound):Void{
_loadedSound.play();
});
| id | The ID or asset path for the file |
| handler | a funtion to handle the loaded music |
| useCache | whether or not to add / retrieve the asset from the cache |
static function loadSound(id:String, handler:Sound ->Void?useCache:Bool = true): Void
Asynchronously loads an instance of a sound. @usage Asset.loadSound("MyReallyShortSong.wav", function(_loadedSound):Void{
_loadedSound.play();
});
| id | The ID or asset path for the file |
| handler | a funtion to handle the loaded sound |
| useCache | whether or not to add / retrieve the asset from the cache |
static function loadText(id:String, handler:String ->Void): Void
Asynchronously loads an instance of an embedded text @usage Asset.loadText("MyReallyLongText.txt", function(_loadedText):Void{
myTextField.text = _loadedText;
});
| id | The ID or asset path for the file |
| handler | a funtion to handle the loaded text |
| useCache | whether or not to add / retrieve the asset from the cache |
static function registerLibrary(name:String, library:AssetLibrary): Void
Registers an AssetLibrary
| name | the name of the library |
| library | the AssetLibrary to register |