Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Assets

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 in the project file.

Hierarchy

  • Assets

Index

Properties

Static cache

Methods

Static addEventListener

  • addEventListener(type: string, listener: any, useCapture?: boolean, priority?: number, useWeakReference?: boolean): void
  • Parameters

    • type: string
    • listener: any
    • Optional useCapture: boolean
    • Optional priority: number
    • Optional useWeakReference: boolean

    Returns void

Static dispatchEvent

  • dispatchEvent(event: Event): boolean

Static exists

  • exists(id: string, type?: AssetType): boolean
  • Returns whether a specific asset exists

    Parameters

    • id: string

      The ID or asset path for the asset

    • Optional type: AssetType

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

    Returns boolean

    Whether the requested asset ID and type exists

Static getBitmapData

  • getBitmapData(id: string, useCache?: boolean): BitmapData
  • Gets an instance of an embedded bitmap

    usage

    bitmap = new Bitmap (Assets.getBitmapData ("image.png"));

    Parameters

    • id: string

      The ID or asset path for the bitmap

    • Optional useCache: boolean

      (Optional) Whether to allow use of the asset cache (Default: true)

    Returns BitmapData

    A new BitmapData object

Static getBytes

  • Gets an instance of an embedded binary asset

    usage

    bytes = Assets.getBytes ("file.zip");

    Parameters

    • id: string

      The ID or asset path for the asset

    Returns ByteArray

    A new ByteArray object

Static getFont

  • getFont(id: string, useCache?: boolean): Font
  • Gets an instance of an embedded font

    usage

    fontName = Assets.getFont ("font.ttf").fontName;

    Parameters

    • id: string

      The ID or asset path for the font

    • Optional useCache: boolean

      (Optional) Whether to allow use of the asset cache (Default: true)

    Returns Font

    A new Font object

Static getLibrary

Static getMovieClip

  • Gets an instance of an included MovieClip

    usage

    movieClip = Assets.getMovieClip ("library:BouncingBall");

    Parameters

    • id: string

      The ID for the MovieClip

    Returns MovieClip

    A new MovieClip object

Static getPath

  • getPath(id: string): string
  • Gets the file path (if available) for an asset

    usage

    path = Assets.getPath ("file.txt");

    Parameters

    • id: string

      The ID or asset path for the asset

    Returns string

    The path to the asset, or null if it does not exist

Static getSound

  • getSound(id: string, useCache?: boolean): Sound
  • Gets an instance of an embedded sound

    usage

    sound = Assets.getSound ("sound.wav");

    Parameters

    • id: string

      The ID or asset path for the sound

    • Optional useCache: boolean

      (Optional) Whether to allow use of the asset cache (Default: true)

    Returns Sound

    A new Sound object

Static getText

  • getText(id: string): string
  • Gets an instance of an embedded text asset

    usage

    text = Assets.getText ("text.txt");

    Parameters

    • id: string

      The ID or asset path for the asset

    Returns string

    A new String object

Static hasEventListener

  • hasEventListener(type: string): boolean

Static hasLibrary

  • hasLibrary(name: string): boolean

Static isLocal

  • isLocal(id: string, type?: AssetType, useCache?: boolean): boolean
  • Returns whether an asset is "local", and therefore can be loaded synchronously

    Parameters

    • id: string

      The ID or asset path for the asset

    • Optional type: AssetType

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

    • Optional useCache: boolean

      (Optional) Whether to allow use of the asset cache (Default: true)

    Returns boolean

    Whether the asset is local

Static list

  • Returns a list of all embedded assets (by type)

    Parameters

    • Optional type: AssetType

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

    Returns Array<String>

    An array of asset ID values

Static loadBitmapData

  • Loads an included bitmap asset asynchronously

    usage

    Assets.loadBitmapData ("image.png").onComplete (handleImage);

    Parameters

    • id: string

      The ID or asset path for the asset

    • Optional useCache: boolean | null

      (Optional) Whether to allow use of the asset cache (Default: true)

    Returns Future<BitmapData>

    Returns a Future

Static loadBytes

  • Loads an included byte asset asynchronously

    usage

    Assets.loadBytes ("file.zip").onComplete (handleBytes);

    Parameters

    • id: string

      The ID or asset path for the asset

    Returns Future<ByteArray>

    Returns a Future

Static loadFont

  • loadFont(id: string, useCache?: boolean | null): Future<Font>
  • Loads an included font asset asynchronously

    usage

    Assets.loadFont ("font.ttf").onComplete (handleFont);

    Parameters

    • id: string

      The ID or asset path for the asset

    • Optional useCache: boolean | null

      (Optional) Whether to allow use of the asset cache (Default: true)

    Returns Future<Font>

    Returns a Future

Static loadLibrary

Static loadMovieClip

  • Loads an included MovieClip asset asynchronously

    usage

    Assets.loadMovieClip ("library:BouncingBall").onComplete (handleMovieClip);

    Parameters

    • id: string

      The ID for the asset

    Returns Future<MovieClip>

    Returns a Future

Static loadMusic

  • loadMusic(id: string, useCache?: boolean | null): Future<Sound>
  • Loads an included music asset asynchronously

    usage

    Assets.loadMusic ("music.ogg").onComplete (handleMusic);

    Parameters

    • id: string

      The ID or asset path for the asset

    • Optional useCache: boolean | null

      (Optional) Whether to allow use of the asset cache (Default: true)

    Returns Future<Sound>

    Returns a Future

Static loadSound

  • loadSound(id: string, useCache?: boolean | null): Future<Sound>
  • Loads an included sound asset asynchronously

    usage

    Assets.loadSound ("sound.wav").onComplete (handleSound);

    Parameters

    • id: string

      The ID or asset path for the asset

    • Optional useCache: boolean | null

      (Optional) Whether to allow use of the asset cache (Default: true)

    Returns Future<Sound>

    Returns a Future

Static loadText

  • loadText(id: string): Future<String>
  • Loads an included text asset asynchronously

    usage

    Assets.loadText ("text.txt").onComplete (handleString);

    Parameters

    • id: string

      The ID or asset path for the asset

    Returns Future<String>

    Returns a Future

Static registerLibrary

  • registerLibrary(name: string, library: AssetLibrary): void
  • Registers a new AssetLibrary with the Assets class

    Parameters

    • name: string

      The name (prefix) to use for the library

    • library: AssetLibrary

      An AssetLibrary instance to register

    Returns void

Static removeEventListener

  • removeEventListener(type: string, listener: any, capture?: boolean): void

Static unloadLibrary

  • unloadLibrary(name: string): void

Generated using TypeDoc