Skip to main content

Assets

Kindclass
Packageopenfl.utils
Full nameopenfl.utils.Assets
Sourcesource/source-haxelib-patches/openfl/utils/Assets.hx
Metadata@:fileXml('tags="haxe,release"') @:noDebug @:access(openfl.display.BitmapData) @:access(openfl.display.Sprite) @:access(openfl.text.Font) @:access(openfl.utils.AssetLibrary)

Public fields​

NameTypeStaticDefaultNotes
cacheIAssetCacheyesnew AssetCache()—

Public methods​

addEventListener​

static function addEventListener(type:String, listener:Dynamic, useCapture:Bool = false, priority:Int = 0, useWeakReference:Bool = false):Void
ParameterTypeDefault
typeString—
listenerDynamic—
useCapture (optional)Boolfalse
priority (optional)Int0
useWeakReference (optional)Boolfalse

View source

dispatchEvent​

static function dispatchEvent(event:Event):Bool
ParameterTypeDefault
eventEvent—

View source

exists​

static function exists(id:String, type:AssetType = null):Bool

Returns whether a specific asset exists @param id The ID or asset path for the asset @param type The asset type to match, or null to match any type @return Whether the requested asset ID and type exists

ParameterTypeDefault
idString—
type (optional)AssetTypenull

View source

getBitmapData​

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")); @param id The ID or asset path for the bitmap @param useCache (Optional) Whether to allow use of the asset cache (Default: true) @return A new BitmapData object

ParameterTypeDefault
idString—
useCache (optional)Booltrue

View source

getBytes​

static function getBytes(id:String):ByteArray

Gets an instance of an embedded binary asset @usage var bytes = Assets.getBytes ("file.zip"); @param id The ID or asset path for the asset @return A new ByteArray object

ParameterTypeDefault
idString—

View source

getFont​

static function getFont(id:String, useCache:Bool = true):Font

Gets an instance of an embedded font @usage var fontName = Assets.getFont ("font.ttf").fontName; @param id The ID or asset path for the font @param useCache (Optional) Whether to allow use of the asset cache (Default: true) @return A new Font object

ParameterTypeDefault
idString—
useCache (optional)Booltrue

View source

getLibrary​

static function getLibrary(name:String):#if lime LimeAssetLibrary #else AssetLibrary #end
ParameterTypeDefault
nameString—

View source

getMovieClip​

static function getMovieClip(id:String):MovieClip

Gets an instance of an included MovieClip @usage var movieClip = Assets.getMovieClip ("library:BouncingBall"); @param id The ID for the MovieClip @return A new MovieClip object

ParameterTypeDefault
idString—

View source

getMusic​

static function getMusic(id:String, useCache:Bool = true):Sound
ParameterTypeDefault
idString—
useCache (optional)Booltrue

View source

getPath​

static function getPath(id:String):String

Gets the file path (if available) for an asset @usage var path = Assets.getPath ("file.txt"); @param id The ID or asset path for the asset @return The path to the asset, or null if it does not exist

ParameterTypeDefault
idString—

View source

getSound​

static function getSound(id:String, useCache:Bool = true):Sound

Gets an instance of an embedded sound @usage var sound = Assets.getSound ("sound.wav"); @param id The ID or asset path for the sound @param useCache (Optional) Whether to allow use of the asset cache (Default: true) @return A new Sound object

ParameterTypeDefault
idString—
useCache (optional)Booltrue

View source

getText​

static function getText(id:String):String

Gets an instance of an embedded text asset @usage var text = Assets.getText ("text.txt"); @param id The ID or asset path for the asset @return A new String object

ParameterTypeDefault
idString—

View source

hasEventListener​

static function hasEventListener(type:String):Bool
ParameterTypeDefault
typeString—

View source

hasLibrary​

static function hasLibrary(name:String):Bool
ParameterTypeDefault
nameString—

View source

initBinding​

static function initBinding(className:String, instance:Dynamic = null):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`.
@param className The registered class name of the asset constructor
@param instance The current class instance to be bound (default is null)
@return Whether asset binding was successful
ParameterTypeDefault
classNameString—
instance (optional)Dynamicnull

View source

isLocal​

static function isLocal(id:String, type:AssetType = null, useCache:Bool = true):Bool

Returns whether an asset is "local", and therefore can be loaded synchronously @param id The ID or asset path for the asset @param type The asset type to match, or null to match any type @param useCache (Optional) Whether to allow use of the asset cache (Default: true) @return Whether the asset is local

ParameterTypeDefault
idString—
type (optional)AssetTypenull
useCache (optional)Booltrue

View source

list​

static function list(type:AssetType = null):Array<String>

Returns a list of all embedded assets (by type) @param type The asset type to match, or null to match any type @return An array of asset ID values

ParameterTypeDefault
type (optional)AssetTypenull

View source

loadBitmapData​

static function loadBitmapData(id:String, useCache:Null<Bool> = true):Future<BitmapData>

Loads an included bitmap asset asynchronously @usage Assets.loadBitmapData ("image.png").onComplete (handleImage); @param id The ID or asset path for the asset @param useCache (Optional) Whether to allow use of the asset cache (Default: true) @return Returns a Future<BitmapData>

ParameterTypeDefault
idString—
useCache (optional)Null<Bool>true

View source

loadBytes​

static function loadBytes(id:String):Future<ByteArray>

Loads an included byte asset asynchronously @usage Assets.loadBytes ("file.zip").onComplete (handleBytes); @param id The ID or asset path for the asset @return Returns a Future<ByteArray>

ParameterTypeDefault
idString—

View source

loadFont​

static function loadFont(id:String, useCache:Null<Bool> = true):Future<Font>

Loads an included font asset asynchronously @usage Assets.loadFont ("font.ttf").onComplete (handleFont); @param id The ID or asset path for the asset @param useCache (Optional) Whether to allow use of the asset cache (Default: true) @return Returns a Future<Font>

ParameterTypeDefault
idString—
useCache (optional)Null<Bool>true

View source

loadLibrary​

static function loadLibrary(name:String):#if java Future<LimeAssetLibrary> #else Future<AssetLibrary> #end

Load an included AssetLibrary @param name The name of the AssetLibrary to load @return Returns a Future<AssetLibrary>

ParameterTypeDefault
nameString—

View source

loadMusic​

static function loadMusic(id:String, useCache:Null<Bool> = true):Future<Sound>

Loads an included music asset asynchronously @usage Assets.loadMusic ("music.ogg").onComplete (handleMusic); @param id The ID or asset path for the asset @param useCache (Optional) Whether to allow use of the asset cache (Default: true) @return Returns a Future<Sound>

ParameterTypeDefault
idString—
useCache (optional)Null<Bool>true

View source

loadMovieClip​

static function loadMovieClip(id:String):Future<MovieClip>

Loads an included MovieClip asset asynchronously @usage Assets.loadMovieClip ("library:BouncingBall").onComplete (handleMovieClip); @param id The ID for the asset @param useCache (Optional) Whether to allow use of the asset cache (Default: true) @return Returns a Future<MovieClip>

ParameterTypeDefault
idString—

View source

loadSound​

static function loadSound(id:String, useCache:Null<Bool> = true):Future<Sound>

Loads an included sound asset asynchronously @usage Assets.loadSound ("sound.wav").onComplete (handleSound); @param id The ID or asset path for the asset @param useCache (Optional) Whether to allow use of the asset cache (Default: true) @return Returns a Future<Sound>

ParameterTypeDefault
idString—
useCache (optional)Null<Bool>true

View source

loadText​

static function loadText(id:String):Future<String>

Loads an included text asset asynchronously @usage Assets.loadText ("text.txt").onComplete (handleString); @param id The ID or asset path for the asset @param useCache (Optional) Whether to allow use of the asset cache (Default: true) @return Returns a Future<String>

ParameterTypeDefault
idString—

View source

registerBinding​

static function registerBinding(className:String, library:AssetLibrary):Void

Registers an AssetLibrary binding for use with @:bind or Assets.bind @param className The class name to use for the binding @param method The AssetLibrary responsible for the binding

ParameterTypeDefault
classNameString—
libraryAssetLibrary—

View source

registerLibrary​

static function registerLibrary(name:String, library:AssetLibrary):Void

Registers a new AssetLibrary with the Assets class @param name The name (prefix) to use for the library @param library An AssetLibrary instance to register

ParameterTypeDefault
nameString—
libraryAssetLibrary—

View source

removeEventListener​

static function removeEventListener(type:String, listener:Dynamic, capture:Bool = false):Void
ParameterTypeDefault
typeString—
listenerDynamic—
capture (optional)Boolfalse

View source

unloadLibrary​

static function unloadLibrary(name:String):Void
ParameterTypeDefault
nameString—

View source

unregisterBinding​

static function unregisterBinding(className:String, library:AssetLibrary):Void

Unregisters an AssetLibrary binding for use with @:bind or Assets.bind @param className The class name to use for the binding @param method The AssetLibrary responsible for the binding

ParameterTypeDefault
classNameString—
libraryAssetLibrary—

View source

Internals​

Private / internal members
FieldTypeStatic
libraryBindingsMap<String, AssetLibrary>yes