Packagekm.core
Classpublic final class AssetManager

The AssetManager class is used to handle assets in a global context so they can be shared by multiple components.
The AssetManager class should not be instantiated !



Public Properties
 PropertyDefined by
  messenger : EventDispatcher
[static] Broadcasts a 'complete' or 'ioError' event when the loading process ends.
You can add a listener to the messenger to receive one of the events.
AssetManager
  namePrefix : String
[static] The asset name prefix to use.
Using a prefix makes it easier to handle a lot of assets that start with the same part.
AssetManager
  suppressNotFoundError : Boolean = false
[static] When set to true, no error is thrown when you try to get an asset that can't be found.
AssetManager
Public Methods
 MethodDefined by
  
getAsset(name:String, usePrefix:Boolean = true):*
[static] Returns the specified asset.
AssetManager
  
getQueueCurrent():String
[static] Returns the name from the queue item that is currently being loaded.
AssetManager
  
[static] Returns the percentage loaded from the queue item that is currently being loaded.
AssetManager
  
[static] Returns the number of items the queue contains.
AssetManager
  
isAsset(name:String, usePrefix:Boolean = true):Boolean
[static] Returns true if the asset exists.
AssetManager
  
loadBinaries(... binaries):void
[static] Adds all specified binaries to the queue and starts loading them.
AssetManager
  
loadImages(... images):void
[static] Adds all specified images to the queue and starts loading them.
AssetManager
  
loadSounds(... mp3s):void
[static] Adds all specified sounds to the queue and starts loading them.
AssetManager
  
registerBitmapDataAsset(asset:BitmapData, name:String, area:Rectangle = null, usePrefix:Boolean = true):void
[static] Registers a BitmapData asset.
AssetManager
Property detail
messengerproperty
public static var messenger:EventDispatcher

Broadcasts a 'complete' or 'ioError' event when the loading process ends.
You can add a listener to the messenger to receive one of the events.


Example
 import km.core.*;

 AssetManager.loadImages('my1stImage.png', 'my2ndImage.png');
 AssetManager.messenger.addEventListener('complete', loadComplete);

 function loadComplete(e:Event){
  play();
 }

 stop();
 

namePrefixproperty 
public static var namePrefix:String

The asset name prefix to use.
Using a prefix makes it easier to handle a lot of assets that start with the same part. If for example a lot of assets start with 'km.themes.classic.' you don't have to type that all the time.

suppressNotFoundErrorproperty 
public static var suppressNotFoundError:Boolean = false

When set to true, no error is thrown when you try to get an asset that can't be found.

Method detail
getAsset()method
public static function getAsset(name:String, usePrefix:Boolean = true):*

Returns the specified asset. If the specified asset is a class, it will be registered automatically as an asset.

Parameters
name:String
 
usePrefix:Boolean (default = true)

Returns
*
getQueueCurrent()method 
public static function getQueueCurrent():String

Returns the name from the queue item that is currently being loaded.

Returns
String
getQueueCurrentPercentage()method 
public static function getQueueCurrentPercentage():uint

Returns the percentage loaded from the queue item that is currently being loaded.

Returns
uint
getQueueLength()method 
public static function getQueueLength():uint

Returns the number of items the queue contains.

Returns
uint
isAsset()method 
public static function isAsset(name:String, usePrefix:Boolean = true):Boolean

Returns true if the asset exists.

Parameters
name:String
 
usePrefix:Boolean (default = true)

Returns
Boolean
loadBinaries()method 
public static function loadBinaries(... binaries):void

Adds all specified binaries to the queue and starts loading them.

Parameters
... binaries
loadImages()method 
public static function loadImages(... images):void

Adds all specified images to the queue and starts loading them.

Parameters
... images

Example
 import km.core.*;

 var AM:Object = AssetManager;
 AM.loadImages('button.png','checkbox.png');

 var tf:TextField = new TextField();
 tf.defaultTextFormat = new TextFormat('_sans');
 tf.autoSize = 'left';
 tf.x = 20;
 tf.y = 20;
 addChild(tf);

 addEventListener('enterFrame', enterFrame);
 function enterFrame(e:Event){
  if (!AM.getQueueLength()){
   removeEventListener('enterFrame', enterFrame);
   removeChild(tf);
   play();
  } else {
   tf.text = 'Loading asset : ' + AM.getQueueCurrent();
   tf.appendText('\nAssets remaining : ' + AM.getQueueLength());
  }
 }

 stop();
 

loadSounds()method 
public static function loadSounds(... mp3s):void

Adds all specified sounds to the queue and starts loading them.

Parameters
... mp3s
registerBitmapDataAsset()method 
public static function registerBitmapDataAsset(asset:BitmapData, name:String, area:Rectangle = null, usePrefix:Boolean = true):void

Registers a BitmapData asset. This function gives you the freedom to register a BitmapData object created at runtime as an asset. The area parameter allows you to specify what part of the specified bitmap should be registered.

Parameters
asset:BitmapData
 
name:String
 
area:Rectangle (default = null)
 
usePrefix:Boolean (default = true)