Packagestarling.utils
Classpublic class AssetManager
InheritanceAssetManager Inheritance Object

The AssetManager handles loading and accessing a variety of asset types. You can add assets directly (via the 'add...' methods) or asynchronously via a queue. This allows you to deal with assets in a unified way, no matter if they are loaded from a file, directory, URL, or from an embedded object.

If you load files from disk, the following types are supported: png, jpg, atf, mp3, xml, fnt



Public Properties
 PropertyDefined By
  scaleFactor : Number
Textures that are created from Bitmaps or ATF files will have the scale factor assigned here.
AssetManager
  useMipMaps : Boolean
For bitmap textures, this flag indicates if mip maps should be generated when they are loaded; for ATF textures, it indicates if mip maps are valid and should be used.
AssetManager
  verbose : Boolean
When activated, the class will trace information about added/enqueued assets.
AssetManager
Public Methods
 MethodDefined By
  
AssetManager(scaleFactor:Number = -1, useMipmaps:Boolean = false)
Create a new AssetManager.
AssetManager
  
addSound(name:String, sound:Sound):void
Register a sound under a certain name.
AssetManager
  
addTexture(name:String, texture:Texture):void
Register a texture under a certain name.
AssetManager
  
addTextureAtlas(name:String, atlas:TextureAtlas):void
Register a texture atlas under a certain name.
AssetManager
  
dispose():void
Disposes all contained textures.
AssetManager
  
enqueue(... rawAssets):void
Enqueues one or more raw assets; they will only be available after successfully executing the "loadQueue" method.
AssetManager
  
getSound(name:String):Sound
Returns a sound with a certain name.
AssetManager
  
getSoundNames(prefix:String):Vector.<String>
Returns all sound names that start with a certain string, sorted alphabetically.
AssetManager
  
getTexture(name:String):Texture
Returns a texture with a certain name.
AssetManager
  
Returns a texture atlas with a certain name, or null if it's not found.
AssetManager
  
getTextureNames(prefix:String, result:Vector.<String> = null):Vector.<String>
Returns all texture names that start with a certain string, sorted alphabetically.
AssetManager
  
getTextures(prefix:String, result:Vector.<Texture> = null):Vector.<Texture>
Returns all textures that start with a certain string, sorted alphabetically (especially useful for "MovieClip").
AssetManager
  
loadQueue(onProgress:Function):void
Loads all enqueued assets asynchronously.
AssetManager
  
playSound(name:String, startTime:Number = 0, loops:int = 0, transform:SoundTransform = null):SoundChannel
Generates a new SoundChannel object to play back the sound.
AssetManager
  
purge():void
Removes assets of all types and empties the queue.
AssetManager
  
removeSound(name:String):void
Removes a certain sound.
AssetManager
  
removeTexture(name:String, dispose:Boolean = true):void
Removes a certain texture, optionally disposing it.
AssetManager
  
removeTextureAtlas(name:String, dispose:Boolean = true):void
Removes a certain texture atlas, optionally disposing it.
AssetManager
Property Detail
scaleFactorproperty
scaleFactor:Number

Textures that are created from Bitmaps or ATF files will have the scale factor assigned here.


Implementation
    public function get scaleFactor():Number
    public function set scaleFactor(value:Number):void
useMipMapsproperty 
useMipMaps:Boolean

For bitmap textures, this flag indicates if mip maps should be generated when they are loaded; for ATF textures, it indicates if mip maps are valid and should be used.


Implementation
    public function get useMipMaps():Boolean
    public function set useMipMaps(value:Boolean):void
verboseproperty 
verbose:Boolean

When activated, the class will trace information about added/enqueued assets.


Implementation
    public function get verbose():Boolean
    public function set verbose(value:Boolean):void
Constructor Detail
AssetManager()Constructor
public function AssetManager(scaleFactor:Number = -1, useMipmaps:Boolean = false)

Create a new AssetManager. The 'scaleFactor' and 'useMipmaps' parameters define how enqueued bitmaps will be converted to textures.

Parameters
scaleFactor:Number (default = -1)
 
useMipmaps:Boolean (default = false)
Method Detail
addSound()method
public function addSound(name:String, sound:Sound):void

Register a sound under a certain name. It will be availble right away.

Parameters

name:String
 
sound:Sound

addTexture()method 
public function addTexture(name:String, texture:Texture):void

Register a texture under a certain name. It will be availble right away.

Parameters

name:String
 
texture:Texture

addTextureAtlas()method 
public function addTextureAtlas(name:String, atlas:TextureAtlas):void

Register a texture atlas under a certain name. It will be availble right away.

Parameters

name:String
 
atlas:TextureAtlas

dispose()method 
public function dispose():void

Disposes all contained textures.

enqueue()method 
public function enqueue(... rawAssets):void

Enqueues one or more raw assets; they will only be available after successfully executing the "loadQueue" method. This method accepts a variety of different objects:

Suitable object names are extracted automatically: A file named "image.png" will be accessible under the name "image". When enqueuing embedded assets via a class, the variable name of the embedded object will be used as its name. An exception are texture atlases: they will have the same name as the actual texture they are referencing.

Parameters

... rawAssets

getSound()method 
public function getSound(name:String):Sound

Returns a sound with a certain name.

Parameters

name:String

Returns
Sound
getSoundNames()method 
public function getSoundNames(prefix:String):Vector.<String>

Returns all sound names that start with a certain string, sorted alphabetically.

Parameters

prefix:String

Returns
Vector.<String>
getTexture()method 
public function getTexture(name:String):Texture

Returns a texture with a certain name. The method first looks through the directly added textures; if no texture with that name is found, it scans through all texture atlases.

Parameters

name:String

Returns
Texture
getTextureAtlas()method 
public function getTextureAtlas(name:String):TextureAtlas

Returns a texture atlas with a certain name, or null if it's not found.

Parameters

name:String

Returns
TextureAtlas
getTextureNames()method 
public function getTextureNames(prefix:String, result:Vector.<String> = null):Vector.<String>

Returns all texture names that start with a certain string, sorted alphabetically.

Parameters

prefix:String
 
result:Vector.<String> (default = null)

Returns
Vector.<String>
getTextures()method 
public function getTextures(prefix:String, result:Vector.<Texture> = null):Vector.<Texture>

Returns all textures that start with a certain string, sorted alphabetically (especially useful for "MovieClip").

Parameters

prefix:String
 
result:Vector.<Texture> (default = null)

Returns
Vector.<Texture>
loadQueue()method 
public function loadQueue(onProgress:Function):void

Loads all enqueued assets asynchronously. The 'onProgress' function will be called with a 'ratio' between '0.0' and '1.0', with '1.0' meaning that it's complete.

Parameters

onProgress:Functionfunction(ratio:Number):void;

playSound()method 
public function playSound(name:String, startTime:Number = 0, loops:int = 0, transform:SoundTransform = null):SoundChannel

Generates a new SoundChannel object to play back the sound. This method returns a SoundChannel object, which you can access to stop the sound and to control volume.

Parameters

name:String
 
startTime:Number (default = 0)
 
loops:int (default = 0)
 
transform:SoundTransform (default = null)

Returns
SoundChannel
purge()method 
public function purge():void

Removes assets of all types and empties the queue.

removeSound()method 
public function removeSound(name:String):void

Removes a certain sound.

Parameters

name:String

removeTexture()method 
public function removeTexture(name:String, dispose:Boolean = true):void

Removes a certain texture, optionally disposing it.

Parameters

name:String
 
dispose:Boolean (default = true)

removeTextureAtlas()method 
public function removeTextureAtlas(name:String, dispose:Boolean = true):void

Removes a certain texture atlas, optionally disposing it.

Parameters

name:String
 
dispose:Boolean (default = true)